Sleep function in server side script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2017 07:51 AM
In my server side script, I am triggering an action via an outbound ReST call. The asynchronous operation returns immediately, but provides a URL which I can poll for the operation's completion. I would like to keep the function atomic, so would like to poll the URL, and if the operation hasn't yet completed, would like to wait for a second or so and poll again, and do that for several times (I do not expect the operation to take more than 10-20 seconds, normally not more than 5 seconds) until done.
I am looking for something like setTimeout or setInterval function that I could use on the server, so that I can tell my script to wait, but can't find anything. Am I missing something? Can somebody point me to a solution for this kind of problem?
I have seen a timer activity in Workflow, which would pause the workflow for a specified period of time; it can probably serve as a workaround, but I wanted a programmatic (and programmable) solution. Will be grateful for any guidance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2017 07:54 AM
Have you taken a look at gs.sleep(milliseconds)?
http://wiki.servicenow.com/index.php?title=GlideElement#gsc.tab=0
I should also mention that it's only available to global apps (not scoped.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2017 08:05 AM
Yes, I saw that function, and also saw that it's only available to global apps. I have a scoped application, so am not able to use gs.sleep() :-(.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2017 08:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2017 08:17 AM
I like the idea of using callbacks, but how do I do that in my situation? I am invoking a third party operation, they provide URL for polling. The only API I can use is ReST. How can I solve my conundrum?