- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 03:38 AM
Hi,
can anyone please tell how can I introduce a specified time delay between two commands.
example
I need an alternative of Sleep command.
var max_retries = 10; //5 minutes, 30 seconds apart for each try
var max_retries_counter = 0;
var employeeID = "";
//Check if the employeeID is valid
if (employeeID.charAt(0) == "X") {
break;
} else {
max_retries_counter ++;
sleep(30000); //30 seconds
}
}
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 03:42 AM
Hi,
I have used this in past and it works well
delay of 10 seconds
var seconds = parseInt(10, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
while(start>parseInt(new Date().getTime())){
// do nothing
}
OR
ms -> milliseconds
function sleep(ms) {
var endSleep = new GlideDuration().getNumericValue() + ms;
while ( new GlideDuration().getNumericValue() < endSleep) {
//wait
}
return;
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
can you post a new question for this and share your complete business requirement and script you tried?
Tag me there as this is an old thread.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 04:58 AM
Hi,
you can try below code
var delayInMilliseconds = 10000; //10 seconds
setTimeout(function() {
//your code to be executed after 10 seconds
}, delayInMilliseconds);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 08:35 PM
How did this work for you? For me it said
Evaluator: com.glide.script.RhinoEcmaError: "setTimeout" is not defined.