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.

Need to add delay for Business rule in scoped application

Pavankumar_1
Mega Patron

Hi experts,

Need to add  delay to the business rule in scoped application. using the business rule I am creating the records before creating the records it should wait for some time. for that wait I used the below scripts.

script1:

var when = new GlideDateTime();
var delay = new GlideTime();
delay.setValue("00:02:00");
when.add(delay);

script 2:
gs.sleep(10000); //10 secs

I tried both scripts on Business rules. Please suggest the script to pause BR on scoped application.

 

Thanks,

Pavan

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
6 REPLIES 6

Sai Kumar B
Mega Sage

Hi pavan,

1.) You can try the Async business rule

2.) You can try the below code as well, ms is milliseconds

For reference try @Ankur Bawiskar response from https://community.servicenow.com/community?id=community_question&sys_id=f69322cbdb4cd89c5ed4a851ca96...

function sleep(ms) {
  var endSleep = new GlideDuration().getNumericValue() + ms;
  while ( new GlideDuration().getNumericValue() < endSleep) {
   //wait 
  }

  return;
}

Raghu Ram Y
Kilo Sage

HI,

It's not a best practice to use sleep and delay in scripts, instead make use of scheduled event.