Using Promises inside Fix Scripts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2019 10:11 AM
Hi,
I am working on a Fix Script that is supposed to use asynchronous style coding in order to carry out a lot of outbound REST requests, but I was surprised to see that the Promise identifier could not be found ? The line is log says:
ReferenceError: "Promise" is not defined.
and basically I have something like this that is part of the Script Include:
new Promise(function(resolve, reject) {
});
Is there something I'm missing here or promises really can't be used inside fix scripts ? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 12:31 PM
I am having the same issue. Have you figured out if this is expected behavior?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 12:39 PM
Please check this and see if it helps
http://www.john-james-andersen.com/blog/service-now/angular-servicenow-tutorial-4-promises.html
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2019 12:00 AM
Well not really. For my problem, I found that using a scheduled script that executes every few minutes would be a better solution anyway. Regarding Promises - JS on the server side is actually executed on the old Rhino interpreter (like from 2008) which doesn't have any support for async related operations(setTimeout, Promise etc). Later on, I found that by default the app is executing in Compatibility Mode (System Applications -> Applications > Your Application -> JavaScript Mode) and there is an option to choose ES5. I haven't tried this, it might add support for some async operations like setTimeout/setInterval, but I doubt that Promises would still work as they are an ES6 concept. Good luck, and please let me know if you find solution for your problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2021 09:30 AM
If the purpose is wait a time for the next execution you can just use the synchronized function:
var seconds = 10;
gs.sleep(seconds*1000);
Or you can try to use callback instead of Promise
function wait(time, callback) {
gs.sleep(time);
if (callback && (typeof callback == "function")) {
return callback();
}
}