How to Delay Business Rule for some time

swaroop
Kilo Sage

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.

12 REPLIES 12

Prasad Pagar
Mega Sage

Hi, 

Is it for custom app? or global app?

What you have in scripts?

Thank you
Prasad

Also see the solution suggested by Ankur here

https://community.servicenow.com/community?id=community_question&sys_id=fbb0ac3fdb8e48104819fb243996190e

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

Community Alums
Not applicable

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.