Asynchronous Computing with JavaScript Promises
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2016 01:19 PM
ECMA-262 (6th edition) supports promises natively. It is my understanding that ServiceNow uses Mozilla Rhino which is still on ECMA 5. Is there currently any sort of support for promises within the ServiceNow environment?
A simple use case is as follows: I have a large job, Job A, that currently takes around 5 minutes to finish execution. In a Script Include, I am looking to start Job A via a web service. I'd like to use a promise within the Script Include stating, once Job A has completed successfully, run this code. If it fails, run this code, etc. Are there any API's out there that support this type of behavior?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2016 05:20 PM
Wouldn't you be able to do this using a workflow? Sure, it's not the same as promises and not as flexible, but you might be able to achieve what you're describing.
Another possibility that comes to my mind is doing a loopback web service call with callbacks for success and fail cases.
Hope this helps.
Please feel free to connect, follow, mark helpful / answer, like, endorse.
John Chun, PhD PMP ![]() | ![]() |
Winner of November 2016 Members' Choice Award
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2017 08:57 AM
Hey John,
Thanks for the reply. I've considered the workflow idea but was wondering if there is a more efficient way to handle this. Maybe one day ServiceNow will support promises.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 11:18 AM
Servicenow does support promises to implement a promise please see the example code below:
asyncFunction = new function(inputs ........)
return new Promise(function(response, reject){
Some Logic.....
response(output);
Else
reject(output);
})
}
Calling the asyncFunciton:
asyncFunction(input).then(function(res){
Some Logic for succes
}, function(err){
Some Logic for error handling
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2018 03:44 AM
Hi geni,
Have you used this successfully in a ServiceNow environment? What was the context where it was used? Would you mind providing a sample script that's working for you? I'm testing this with a simple example, and it is not working for me in a catalog client script run in the non-portal UI in a Jakarta environment. I could just be missing something, of course.
Thanks!