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.

Alternative of gs.sleep() in Scripted Rest API

mansigoel
Tera Contributor

Hi,

 

I want a delay of 10 seconds in my scripted REST API Script. 

It is working through gs.sleep() -  my usecase is to wait for sc_task to be generated after creation of RITM.

 

But, since this is not a best practice to use gs.sleep() , I want an alternative approach to implement.

 

Can anyone help on this?

1 ACCEPTED SOLUTION

Amitoj Wadhera
Kilo Sage

Hi @mansigoel ,

 

You can use: 

var startTime = new Date().getTime();
                var delay = 10000; // Simulating a delay of 10 seconds 
while (new Date().getTime() < startTime + delay) {
                    // Simulating the delay
                }

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Thanks,

Amitoj Wadhera

View solution in original post

5 REPLIES 5

palanikumar
Giga Sage
Giga Sage

Hi @mansigoel,

Please explain in detail.

  • Is third party system calling your API and you want to delay the response for 10 secs? Delaying API response is not advisable. We should 
  • Or you are calling an API from Workflow or BR? Please explain how you are calling them.
Thank you,
Palani