Can i make a timeout in Scheduled script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 01:40 AM
Hi everyone, my question might be in the wrong category, pls moderators - move it in the right place.
I'm having a scheduled script and as we all know - its executing his script on server side.
var evt = new GlideRecord('sysevent');
evt.initialize();
evt.insert();
//i need a timeout here for about 15 sec
var emails_GR = new GlideRecord('sys_email');
The thing is that after a sysevent is inserted i want to make a timeout, for about 15 sec and after that "quering'" sys_email.
Any chances to realize it?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 01:47 AM
You can try using gs.sleep(5000) // 5 seconds but not a good practice to do
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 01:49 AM
i'll try it before in bg script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 03:01 AM
i noticed that demo code will print all the info after 5 seconds on screen in bg script, instead sequentially. How correct is that?
gs.print('1')
gs.print('2')
gs.print('3')
gs.print('4')
gs.sleep(5000)
gs.print('5')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 01:49 AM
Hi ,
setTimeout is client side Javascript. You use the gs.sleep() but this not best practice
There is good discussion happened check the below link
https://community.servicenow.com/community?id=community_question&sys_id=7da0b3a4dbaf08d0d82ffb243996191a.
Thanks
Chandu Telu
Please Mark ✅ Correct/helpful, if applicable,