- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 12:26 PM - edited 04-12-2024 01:18 PM
All - I am trying to use promises in my ATF step configuration like below, and not able to use it in my script. Is there anything wrong here or missing any? Appreciate any help.
//Allows to SAVE, executing the promise too - but at the end, errors saying myPromise.error is not a function
option1();
myPromise
.error(function() {
option2();
});
//Not allows to SAVE
option1();
myPromise
.catch(function() {
option2();
});
Saw this post - https://www.servicenow.com/community/developer-articles/ecmascript-features-supported-in-servicenow-...
Seems Async, Await, Promises kind of stuffs will not be supported yet. Is there any updates to this?
Would like to know how people are achieving functionalities that should be executed inside SetTimeOut and throw errors outside.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2024 04:35 AM - edited 04-14-2024 04:42 AM
Yes, on the server side, Promises won't work. If your script is a client-side script then support depends on which browser runs the client script (the majority of browsers support Promises these days so they can be used quite safely in client scripts). Seeing that you mentioned your script is an ATF step, you're most likely writing server-side code, which doesn't support Promises. In fact, ServiceNow's Rhino engine has no/very limited support for any asynchronous methods you might be used to from normal engines (eg: setTimeout, setInterval, queueMicrotask, etc.).
In your scenario, it depends on why you're trying to use a Promise here (ie: what async operation are you using here that you expect a promise to be returned from option1)? There are ways to get around ServiceNow's linter to allow you to save (the catch error occurs as the editor thinks you're using a try-catch statement). One way is to use bracket-notation to avoid catch being interpreted as being part of a try-catch block:
option1();
myPromise["catch"](function() {
option2();
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2024 04:35 AM - edited 04-14-2024 04:42 AM
Yes, on the server side, Promises won't work. If your script is a client-side script then support depends on which browser runs the client script (the majority of browsers support Promises these days so they can be used quite safely in client scripts). Seeing that you mentioned your script is an ATF step, you're most likely writing server-side code, which doesn't support Promises. In fact, ServiceNow's Rhino engine has no/very limited support for any asynchronous methods you might be used to from normal engines (eg: setTimeout, setInterval, queueMicrotask, etc.).
In your scenario, it depends on why you're trying to use a Promise here (ie: what async operation are you using here that you expect a promise to be returned from option1)? There are ways to get around ServiceNow's linter to allow you to save (the catch error occurs as the editor thinks you're using a try-catch statement). One way is to use bracket-notation to avoid catch being interpreted as being part of a try-catch block:
option1();
myPromise["catch"](function() {
option2();
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 06:37 AM
I am using in client-side script to manipulate the UI element part of my ATF UI Script.
Seems using Catch like property is doing the trick, working now. Thanks for the help.