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 05:08 AM
Hi Mike,
Thanks for the suggestion, but this wont fit for my requirement. It should be delayed in the BR Itself.
Thanks & Regards,
S.Swaroop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 05:14 AM
I have tried using the below script but still it is not working. can you please suggest me any other option.
(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 05:22 AM
Hi,
I had used this in past and this has worked
var secondsValue = 60; // 1min
var seconds = parseInt(secondsValue, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
while(start>parseInt(new Date().getTime())){
// do nothing
}
Regards
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
‎06-17-2021 05:29 AM
Hello Ankur,
I am using the below script, but it was working. It was not reaching to the script.
var secondsValue = 60; // 1min
var seconds = parseInt(secondsValue, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
while(start>parseInt(new Date().getTime())){
// do nothing
current.u_regulations_flag_2 = true;
current.update;
}
Thanks & Regards,
S.Swaroop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 05:44 AM
Hi,
you want to se the fields once the sleep ends so do this
you need to add those 2 lines outside while
var secondsValue = 60; // 1min
var seconds = parseInt(secondsValue, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
while(start>parseInt(new Date().getTime())){
// do nothing
}
current.u_regulations_flag_2 = true;
current.update;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader