- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 07:04 AM
Is there some kind of function or code that I can use to delay the processing of a business rule?
By default, once a record is updated and the BR condition is met, the script runs immediately.
What I want to do is delay the running of the script for at least 15 seconds.
This BR sends the ticket info to another system (web service/SOAP).
Thank you!
Enrique
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 07:07 AM
There is a method available in global apps called gs.sleep() where you pass the number of milliseconds you want it to wait. You can also write your own method and call it using something like:
//available in global scope
gs.sleep(5000); //5 seconds
// Custom function if you can't use gs.sleep
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;
}
},
Both of these would have an impact on your system since you are calling it on the server. Is there any reason you're unable to send it right away?
Please mark my answer as helpful/correct if it resolved your issue!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 07:07 AM
There is a method available in global apps called gs.sleep() where you pass the number of milliseconds you want it to wait. You can also write your own method and call it using something like:
//available in global scope
gs.sleep(5000); //5 seconds
// Custom function if you can't use gs.sleep
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;
}
},
Both of these would have an impact on your system since you are calling it on the server. Is there any reason you're unable to send it right away?
Please mark my answer as helpful/correct if it resolved your issue!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 07:46 AM
Thanks Elijah for your response. I'll try your suggestion and will mark as correct answer after testing.
The reason why we don't want to send it right away, it's because after the record is inserted (we upsert XML to Planview), the user can immediately approved the ticket (SNOW sends another update to Planview) and what i'm hearing is in this case, the upsert code was still in progress and so we want some kind of delay.
Enrique
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 07:08 AM
Hi,
you can either use some sleep in the script or use async business rule which is processed after some time
use below code to make the script wait for 10 seconds; you can use your own time
this would work in global and scope app as well
var seconds = parseInt(10, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
while(start>parseInt(new Date().getTime())){
// do nothing
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 03:13 AM
Switching the BR to async solved my issue, thanks 🙂