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

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 was also wondering about this in https://www.servicenow.com/community/itsm-forum/xanadu-es12-in-global/td-p/3009263.

Especially in Xanadu where the SN docs state: 

  • Use ECMAScript 2021 (ES12) features in any server-side script.

 

Since I couldn't get ES12 features working in any server-side, I asked SN about it. Excerpt from the response: 

 

At this stage, our development team is working on it and targeted the fix for Zurich release. Will keep you posted on the status.

And also, in regards to the status of the PRB , will check if there is a customer facing document for reference.

 

Seems strange to me that there is no public KB article or any other document about it if it is not working as advertised.

 

Hi @bert-janfransen , 

 

I used 'let' in a Fix script in global scope (made sure ES12 mode is active). Still it shows the error "

Error Description: let is an ECMAScript 6 feature - not supported

"

If I replace let with var or const, it runs without any issues. I am curious to know why it is not allowing to use 'let' even in ES12 mode. Any pointers? 

 

Thanks,

Gopikrishnan

@Gopi22 - it does not work. ServiceNow docs are giving wrong info in this case. I checked from their support. Check my post above or here https://www.servicenow.com/community/itsm-forum/xanadu-es12-in-global/td-p/3009263.

 

 

Sad part is that SN is fully aware of this but they haven't bothered to update the docs or even release a KB article. They told me: "At this stage, our development team is working on it and targeted the fix for Zurich release. ... Please be informed that the feature has been mentioned in the documentation but is not working as expected. For this reason, we have raised a PRB with our Development team and they are working on the issue. At this stage the Known article is internally posted, we will check further with the concerned team to have a customer facing known article for the visibility."

Thank you for the update ! 🙂 

NS
Kilo Sage

ServiceNow finally acknowledged that the feature indeed does not work:

KB1699139 + Related Problem: PRB1794568

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1699139

 

No info on when it'll be fixed though.