- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 05:36 AM
So we're upgrading from Vancouver to Xanadu, finally unlocking ES2021. So let's try this out.
const foo = 'bar';
gs.info(foo)
let foo = 'bar';
gs.info(foo)
Result:
Script compilation error: Script Identifier: null.null.script, Error Description: let is an ECMAScript 6 feature - not supported (null.null.script; line 1), Script ES Level: 0, Interpreted Mode: true
Javascript compiler exception: let is an ECMAScript 6 feature - not supported (null.null.script; line 1) in: let foo = 'bar'; gs.info(foo)
What the....?! Other features like default function parameters and destructuring also do not seem to work. Does anyone know what's going on here?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 04:11 AM
Thanks for your response. I'm running this in global - I know ES2021 has been available awhile in scoped apps, but from Washington DC on, it is supposed to be available in the global scope. And it sort of is - the use of the const keyword works just fine.
I have figured it out though!
In script includes (and business rules, fix scripts, and probably more), you can use ES2021, even in the global scope. The switch to enable it is on by default. The script can be called from a background script.
What you can NOT do, is use ES2021 in background scripts directly - there the ES2021 switch os missing.
So the following script include works:
const test = Class.create();
test.prototype = {
initialize: function() {
const foo = 'const bar';
let foo2 = 'let bar';
gs.info(foo)
gs.info(foo2)
},
};
new test()
*** Script: const bar
*** Script: let bar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 05:38 AM
Pretty sure it's Xanadu, not Xanada 😁

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 06:28 AM
@bert-janfransen I am assuming you are running this script in scoped app ? if yes make sure JavaScript Mode set as "ECMAScript 2021 (ES12)"
eg:
Referehce : ECMAScript 2021 (ES12)
Thanks,
Harsh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 04:11 AM
Thanks for your response. I'm running this in global - I know ES2021 has been available awhile in scoped apps, but from Washington DC on, it is supposed to be available in the global scope. And it sort of is - the use of the const keyword works just fine.
I have figured it out though!
In script includes (and business rules, fix scripts, and probably more), you can use ES2021, even in the global scope. The switch to enable it is on by default. The script can be called from a background script.
What you can NOT do, is use ES2021 in background scripts directly - there the ES2021 switch os missing.
So the following script include works:
const test = Class.create();
test.prototype = {
initialize: function() {
const foo = 'const bar';
let foo2 = 'let bar';
gs.info(foo)
gs.info(foo2)
},
};
new test()
*** Script: const bar
*** Script: let bar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 09:49 AM - edited 12-05-2024 11:00 AM
Very helpful. Thank you! I'm sure you already saw this, but here is a very informative community post by @Willem regarding when/where ES21 can be used. @bert-janfransen
https://www.servicenow.com/community/developer-articles/discover-the-benefits-of-ecmascript-how-es12...