Trying to set a delay in the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2020 09:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2020 09:11 AM
Hi
You can use eventQueueScheduled as gs.sleep is also an option but it is not recommended
var when = new GlideDateTime();
var delay = new GlideTime();
delay.setValue("00:00:05");
when.add(delay);
gs.eventQueueScheduled("event_name", current, "", "", when);
gs.sleep works as below
gs.sleep(<time in milliseconds>)
Also, check this out
https://community.servicenow.com/community?id=community_article&sys_id=2bada4a2db9bf30014d6fb243996193b
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2020 09:35 AM
Hi Ella,
The easiest solution is to try gs.sleep(milliseconds);
If you will re-use it too often, put the below function in a script include and you can call it wherever required with the required delay in milliseconds.
sleep: function(duration) {
gs.sleep(duration);
},
Regards,
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2020 11:55 AM
Hi, adding any sort of delay in a script can result in\contribute to degraded platform performance.
In most circumstances delays are added as an attempt to work around base platform functionality,
and a better approach is to develop solutions that are aligned with the way the platform functions\operates.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2020 02:17 PM
I've tried to put a delay in the script but found it doesn't work too well.
The solution I ended up doing was not to put a delay but to create a scheduled job that'll create an event to trigger an action after a duration.