How to create a delay in record creation

Mi4
Tera Expert

Hello,

I created a business rule to allow approvers to see the attachments added to the application in the portal.(Global)

find_real_file.png

Weirdly, however, we realized that we needed to enforce this business rule before an authorization record would occur.

System log:

find_real_file.png

My boss told me to use 'gs.sleep' as a way to make this delay.(Global)

find_real_file.png

Refer to:

<https://community.servicenow.com/community?id=community_question&sys_id=8cdc8329db9cdbc01dcaf3231f96...>

 

However, it doesn't work well.

Can you point out what is wrong?

 

Regards,

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

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

ms -> milliseconds

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

  return;
}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

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

ms -> milliseconds

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

  return;
}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi,

Thank you for your reply Sorry for the rudimentary confirmation.

Where do you put this code you gave us?

Business rules? Is it a script include?

 

Regards,

Hi,

remove line 3 and 4 from business rule and use this; no need to call script include

var ms = 5000; // 5 seconds

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

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

hi,

Thank you for teach.

By the way, can this 'gs.sleep' perform the same function as the Timer implemented in the following WF?

My requirements ;

I want to delay the processing of this approval user box.

 

Regards,