EXEC_SCRIPT from a Rule will not run.

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Jaymer
Posts: 2450
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

EXEC_SCRIPT from a Rule will not run.

Post by Jaymer »

When saving this BO Rule that contains this:
Screen Shot 2023-02-10 at 2.44.43 PM.png
Screen Shot 2023-02-10 at 2.44.43 PM.png (5.82 KiB) Viewed 1409 times
I get this warning:
Screen Shot 2023-02-10 at 2.44.11 PM.png
Screen Shot 2023-02-10 at 2.44.11 PM.png (21.94 KiB) Viewed 1409 times
At runtime this is shown:
Screen Shot 2023-02-10 at 2.46.08 PM.png
Screen Shot 2023-02-10 at 2.46.08 PM.png (25.57 KiB) Viewed 1409 times
I know why all this is happening, because the JS being called may have an Alert/UI instruction that requires user input.
But it doesn't in my case.
Its just a Notification that displays at the top of the screen and then goes away after a time.

I've used this before in Processes, either started from a Menu or a Button on a Form.
But this is from a Rule in the BO when the BO is getting saved.
Under a specified condition, I want the JS to run to display a msg.

Don't know why I'm having a brain fart on how to get this accomplished.

PS _ Same result for DISPLAY MESSAGE ASYNCH
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
BLOMASKY
Posts: 1471
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: EXEC_SCRIPT from a Rule will not run.

Post by BLOMASKY »

I could be wrong (usually am) but I thought the ONLY user interaction a rule can have is a REPORT ERROR. Anything else has to be in a process.

So, why not have this line of code call a process to run the EXEC_SCRIPT? Yea, I know thats 1 extra line of code and an additional process....

Bruce
Jaymer
Posts: 2450
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: EXEC_SCRIPT from a Rule will not run.

Post by Jaymer »

Ya
Did that
Got the exact same msg at runtime
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
hpl123
Posts: 2594
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: EXEC_SCRIPT from a Rule will not run.

Post by hpl123 »

I have worked around this before but can't remember how. Have you tried having the JS in a JS file and then calling that file instead of calling the JS function directly? (or is that what you are doing).

Another thing you could try is run some JS from the EXEC_SCRIPT that only set a SessionStorage flag e.g Notify=1 and then have another JS script running with setInterval checking every second or so for that flag and executes some JS if its 1 and then reset it back to 0. I can't remember if ALL JS is "blocked" when running EXEC_SCRIPT but if it isn't, this should work even though its a clunky workaround.

A third thing is of course changing the design of the user interaction i.e where it started from etc. etc. and make sure that is a process i.e don't run it at all via rules.

A smarter and better way probably exists, these were just random things coming to my mind when sitting and having lunch and being a bit bored :D.
Henrik (V8 Developer Ed. - Windows)
Jaymer
Posts: 2450
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: EXEC_SCRIPT from a Rule will not run.

Post by Jaymer »

hpl123 wrote: Sat Feb 11, 2023 8:18 am I have worked around this before but can't remember how. Have you tried having the JS in a JS file and then calling that file instead of calling the JS function directly? (or is that what you are doing).
yes, i load JS from /Custom/JS
hpl123 wrote: Sat Feb 11, 2023 8:18 am Another thing you could try is run some JS from the EXEC_SCRIPT that only set a SessionStorage flag e.g Notify=1 and then have another JS script running with setInterval checking every second or so for that flag and executes some JS if its 1 and then reset it back to 0. I can't remember if ALL JS is "blocked" when running EXEC_SCRIPT but if it isn't, this should work even though its a clunky workaround.
How would Aware know to allow some JS and not others? It has no idea what the JS is doing.
hpl123 wrote: Sat Feb 11, 2023 8:18 am A third thing is of course changing the design of the user interaction i.e where it started from etc. etc. and make sure that is a process i.e don't run it at all via rules.
Can't really do this. The rule is in place. Only other option is to add a process "On Save", and then scatter that extra crud all over an app.
There are several places I want to give this simple notification in the app.

Exactly what I'm doing is this:
On a form a user enters any type of field.
On Save of a form a rule checks for a condition and does something (send email, logs something, whatever).
Instead of a Dialog box which slows the user down and requires a click to close, I just use this code:

Code: Select all

function notifyBar(theMsg) {
	if(! $('.alert-box').length) {
		$('<div class="alert-box alert-box-wide alert-box-left success" >' + theMsg + '</div>').prependTo('body').delay(750).fadeOut(300, function() { $('.alert-box').remove(); });
	};
So it shows a msg bar briefly, and then it fades out. Works perfect in my other scenarios.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2450
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: EXEC_SCRIPT from a Rule will not run.

Post by Jaymer »

There was a discussion that covered most of these points/issues 3 years ago:
https://www.awareim.com/forum/viewtopic ... 953#p52953

v8.5 introduced a way for DISPLAY MESSAGE ASYNCH to work IF
you enabled Dynamic and DO NOT Run on Server.

Thats fine, but not for what I'm doing. In my case, that would display the msg ("Email has been sent", for example) before the record was saved. And it might not actually get saved.
So that was a nice improvement, just doesn't apply to me here.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
hpl123
Posts: 2594
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: EXEC_SCRIPT from a Rule will not run.

Post by hpl123 »

Another thing you possibly could do is run some JS when the form is opened up that adds an event listener tied to your save button which then executes when the save button is clicked. For this to work the condition you mention (and all other needed parts) should of course be available to the JS.

This shouldn't be some cumbersome. A better solution for this would be nice i.e Aware removing all of these restrictions on EXEC_SCRIPT when run from a rule.
Henrik (V8 Developer Ed. - Windows)
Jaymer
Posts: 2450
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: EXEC_SCRIPT from a Rule will not run.

Post by Jaymer »

hpl123 wrote: Sat Feb 11, 2023 7:46 pm This shouldn't be some cumbersome. A better solution for this would be nice i.e Aware removing all of these restrictions on EXEC_SCRIPT when run from a rule.
I feel that EXEC_SCRIPT is not your average-user's function.
So if you're gonna use it, its OK to get the warning during development, but its kinda "Use at your own risk" if you go past that.
In my case, I definitely don't want to "Run on Server",
but I can't turn that off unless its Dynamic, which it can't be.

Not sure what would be an easy fix for Vlad.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Post Reply