ES2021 in Xanada - let not working

bert-janfransen
Tera Expert

So we're upgrading from Vancouver to Xanadu, finally unlocking ES2021. So let's try this out.

 

const foo = 'bar';
gs.info(foo)
 
Prints 'bar'. Nice.
 
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?

 

1 ACCEPTED SOLUTION

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)
    },
};
From a background script:
new test()
 
Result:
*** Script: const bar
*** Script: let bar
 

View solution in original post

9 REPLIES 9

bert-janfransen
Tera Expert

Pretty sure it's Xanadu, not Xanada 😁

Harsh Vardhan
Giga Patron

@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: 

ecma set.PNG

 

excma sc.PNG

 

excma.PNG

 

Referehce : ECMAScript 2021 (ES12) 

 

Thanks,

Harsh

 

 

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)
    },
};
From a background script:
new test()
 
Result:
*** Script: const bar
*** Script: let bar
 

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...