gs.sleep() in scoped application?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2015 05:51 AM
Hi,
gs.sleep(0 function is not working in scoped application? Is there any workaround?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago - last edited a month ago
Use of gs.sleep() in ServiceNow server-side scripts is not recommended, because it keeps the program's thread active for the entire duration, and can eventually deplete execution resources on the system if it is re-executed many times in parallel. However for very short-duration waits, use of gs.sleep() might be an acceptable solution.
To make this work from within a scoped app, you'll need to create a small utility script that is a) global scope, and b) accessible from all scopes. E.g.:
var SleepForScopedApp = Class.create();
SleepForScopedApp.prototype = {
initialize: function(debug) {
this.debug = debug;
},
/**
* Sleep for the provided number of seconds.
*/
sleep: function(secs) {
this.debug && gs.info("Sleeping for " + secs + " secs");
// gs.sleep() parameter is in msecs
gs.sleep(secs * 1000);
this.debug && gs.info("Done sleeping");
},
type: 'SleepForScopedApp'
};
