With business rules Is it possible to delay the execution of the script by about 30 seconds?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2020 06:35 PM
With business rules Is it possible to delay the execution of the script by about 30 seconds?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2020 07:09 PM
Instead of putting a delay in the business rule, create a scheduled job that will create an event after 30 seconds. Create a flow with a script to execute on a trigger.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2020 07:56 PM
Thankyou.
Could you tell me more how to do?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2020 08:28 PM
Hi,
For a similar requirement I created a function to pause execution for a while,
but I wouldn't recommend to use it for longer duration like 30 seconds, but still just in case you need it.
function pause(time){
var t1 = new GlideDateTime().getNumericValue();
var t2 = new GlideDateTime().getNumericValue();
var duration = t2 - t1;
while(duration < time){
t2 = new GlideDateTime().getNumericValue();
duration = t2 - t1;
}
}
Please mark as helpful if it helped.
Gaurang Soni
| https://aavenir.com |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2020 08:44 PM
Hi,
Can you please explain your business use-case/requirement around this
You can delay it by 30seconds something like this
But better way is to use eventQueue() approach
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ms = 30000; // 30 seconds to milliseconds
var endSleep = new GlideDuration().getNumericValue() + ms;
while ( new GlideDuration().getNumericValue() < endSleep) {
//wait
}
// then your logic
})(current, previous);
EventQueue approach:
Instead trigger a scheduled event from your BR which in turn triggers a script action having script to update the metric instance. You can schedule an event to run in future at any given time.
You need to register a new event in event registry. Check this URL
https://developer.servicenow.com/app.do#!/document/content/app_store_learnv2_automatingapps_newyork_...
Put this code in your BR-
var dateTime = new GlideDateTime();
dateTime.addSeconds(30);
gs.eventQueueScheduled("your_event_name", current, "previous_value_to_be_set", "", dateTime);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader