ServiceNow: run an asynchronous script from a business rule

I have a business rule that needs to be run before updating an incident. The problem is that this script has to disable the function from Script Includes "which is slow. I want this call to be asynchronous so that the form can load.

Is there a way to do this?

+3


source to share


2 answers


I assume that you already know about asynchronous business rules and that they don't work for you, because you need to do something synchronously too.

You can use GlideRunScriptJob

from script to execute your script on a background thread. If you already have a script, you simply pass it as a string to a method scheduleScript

in GlideRunScriptJob like so:



var job = new GlideRunScriptJob();
job.scheduleScript("new CustomScriptInclude().foo()");

      

+4


source


You can also do this with script events and actions. So in the business rule, you create an event and attach a script action to that event. The script will run when the event is processed.

If you want to run it in the future, you can use the gs.eventQueueScheduled function to schedule an event to be fired in the future:



gs.eventQueueScheduled (event.name, current, parameter1, parameter2, data and time to fire the event);

+2


source







All Articles