How to Delay Business Rule for some time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 04:50 AM
Hello All,
A Business Rule is there which will trigger based on a condition. But the script in the Business Rule should trigger after some delay of 1minute. When i am using gs.sleep() it is not working.
Can anyone suggest me how to delay the script to run for 1min after theBR triggers based on the condition.
Thanks & Regards,
S.Swaroop.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 04:58 AM
Hi,
Is it for custom app? or global app?
What you have in scripts?
Thank you
Prasad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 04:59 AM
Also see the solution suggested by Ankur here
https://community.servicenow.com/community?id=community_question&sys_id=fbb0ac3fdb8e48104819fb243996190e
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 05:07 AM
Hi Prasad,
I tried using the script suggested by Ankur as you said. But it is not working as expected. Below is the code which i have used.
(function executeRule(current, previous /*null when async*/ ) {
var seconds = parseInt(10, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
while (start > parseInt(new Date().getTime())) {
current.u_regulations_flag_2 = true;
current.update;
}
})(current, previous);
Thanks & Regards,
S.Swaroop

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 04:58 AM
Do not use gs.sleep() in a business rule.
Using sleep keeps control of a thread on the application node, which will lead to an instance outage if you use all the threads.
My suggestion would be that you schedule an event to be processed in 60 seconds time, and use a scripted action to then do whatever you want to do.