Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

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.

swaroop
Kilo Sage

@Ankur Bawiskar Ankur, 

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

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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.

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader