- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 07:46 PM
Hello,
I created a business rule to allow approvers to see the attachments added to the application in the portal.(Global)
Weirdly, however, we realized that we needed to enforce this business rule before an authorization record would occur.
System log:
My boss told me to use 'gs.sleep' as a way to make this delay.(Global)
Refer to:
However, it doesn't work well.
Can you point out what is wrong?
Regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 08:42 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 01:50 AM
Hi,
So do you say you need to add this timer for each workflow?
In other words, can't you implement the delay feature you introduced?
I thought it was inefficient to add a timer to each workflow, and asked a business rule to implement an alternative implementation like a timer.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2021 06:42 AM
Hi Ankur,
I needed to delay the processing of a certain inbound action by 30 seconds and so ended up here. I tried both methods (i.e. gs.sleep(30000) and the one you posted above). Both worked.
I'm wondering why everyone says not to use gs.sleep? I realise in this context it is because you can't use gs.sleep in a scoped app but it seems to be generally advised not to use it.
What is the issue with it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 09:54 PM
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,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 02:06 AM
Hi,
There is a method available in global apps called gs.sleep() where you pass the number of milliseconds you want it to wait. You can also write your own method and call it using something like:
//available in global scope
gs.sleep(5000); //5 seconds
// Custom function if you can't use gs.sleep
function pause(time){
var t1 = new GlideDateTime().getNumericValue();
var t2 = new GlideDateTime().getNumericValue();
var duration = t2 - t1;
while(duration < time){
t2 = new GlideDateTime().getNumericValue();
duration = t2 - t1;
}
},
Both of these would have an impact on your system since you are calling it on the server. Is there any reason you're unable to send it right away?
Please mark my answer as helpful/correct if it resolved your issue!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 06:03 AM
Hello,
Thanks for the code.
I'll give it a try.
Regards,