4

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

Is there any way to do this?

Tommy Steimel
  • 771
  • 8
  • 16

2 Answers2

4

I'm assuming you already know about async business rules, and that those don't work for you because you need to also do something synchronously.

You can use GlideRunScriptJob from script to execute a script on a background thread. If you already have a script, you just pass it as a string to the scheduleScript method on GlideRunScriptJob like so:

var job = new GlideRunScriptJob();
job.scheduleScript("new CustomScriptInclude().foo()");
Joey
  • 2,901
  • 21
  • 22
2

You can also do this using events and script actions. So in the business rule you generate the event and attach a script action to that event. The script will then be run when the event is processed.

If you want to run it in future, you could use gs.eventQueueScheduled function to schedule the event to be triggered some time in the future:

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