logo

NJP

ECMAScript 2021 (ES12) mode in individual script… there's an undocumented catch you need be aware of

Import · Aug 26, 2024 · article

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

Hi there,

It's hard to have missed it, the greater part of Xanadu related content by people is ECMAScript 2021 (ES12) mode in individual script and with that also for the Global scope. There is an undocumented catch no one is sharing though... the toggle for "Turn on ECMAScript 2021 (ES12) mode" is not stored within the record concerned. That is interesting knowledge, though also a good need to know!

Let's have a closer look.

Tokyo: ECMAScript 2021 (ES12) for Scoped Applications

With the Tokyo release, ServiceNow brought a major update to the JavaScript language available. Not by default, though for Scoped Applications developers have the option to choose the JavaScript mode. JavaScript mode option ES5 (Helsinki) and ES21 (Tokyo).

es12_01.png

Xanadu: ECMAScript 2021 (ES12) mode in individual script

With the Xanadu release, ServiceNow has made ECMAScript 2021 (ES12) mode available for individual scripts and with that also for the Global scope! Basically on every individual script field for applications that use ES5 mode (or Compatibility mode), above the script field a toggle "Turn on ECMAScript 2021 (ES12) mode" will be visible. When the toggle is green, ECMAScript 2021 is turned on.

es12_02.png

ES Latest Scripts (sys_es_latest_script)

When you use the toggle to turn ECMAScript 2021 on or off, where is it stored though? Looking at records with a script field, there's no field indicating storing the toggle value. See here an example of the Fix Script table and its fields. Nothing to see about the toggle value for ECMAScript 2021.

es12_03.png

Looking into the XML of a Fix Script though (in an instance, not an exported XML!), we do notice something with "es_latest_script".

es12_04.png

The more experienced ServiceNow people know enough with the previous image. "sys_es_latest_script" is a table name and it's own sys_id is mentioned. So ServiceNow choose to store the toggle value for ECMAScript 2021 in a new table. A bit similar like what you might have seen on different places in any instance, like with price fields.

Here an example of a record in the new "ES Latest Scripts" table [sys_es_latest_script]. The table basically contains the sys_id of the target record, the table of the target record, and a true/false field that represents if the ECMAScript 2021 toggle is on or off.

es12_05.png

Food for thought

So why is it interesting to share this small piece of undocumented knowledge on ECMAScript 2021 (ES12) mode in individual script? This article is not just for fun and to document the undocumented :grinning_face:. In most cases, you won't need to know of the new ES Latest Scripts table, though there are a few situations you do want to know of this!

I'll share two situations. Maybe you can come up with more, do share in the comments!

1) When working on records with a script field, and wanting to do something with the value of the ECMA2021 toggle (updating it, reporting on it)... you would need to do so against the ES Latests Scripts table.

2) The value of the ECMA2021 toggle on a record is not exported via XML export. When importing the XML file on a different instance for example, the value of the ECMA2021 toggle will always be false as it is not part of the XML export. This might brake scripting where the value of the ECMA2021 toggle was set to true!

The XML export feature is designed to work for exporting records from a table as is (raw data), without dependents such as the value of the ECMA2021 toggle.

This behavior is as intended.

Also read this ServiceNow Support article that is on Currency type fields, which have a similar structure.

---

That's it. Hope you like it. If any questions or remarks, let me know!

Kind regards,

Mark Roethof

Independent ServiceNow Consultant

9x ServiceNow MVP

---

View original source

https://www.servicenow.com/community/now-platform-articles/ecmascript-2021-es12-mode-in-individual-script-there-s-an/ta-p/3026751