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

Sulabh Garg
Mega Sage
Mega Sage

Hello

In scoped app, gs.sleep() is not allowed you can use this to use some delay

ms means milliseconds here

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

  return;
}

Please Mark âś… Correct/helpful, if applicable, Thanks!! 

Regards

Sulabh Garg

Please Mark âś… Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

this works in scoped app

var seconds = parseInt(10, 10) * 1000; // 10 seconds delay

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

@pavan

I have shared solution here 2 years ago

How to create a delay in record creation

Regards
Ankur

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

@Pavan 

Thank you for marking my response as helpful.

Please mark appropriate response as correct and close the thread so that it benefits future readers.

Regards
Ankur

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