Willem
Giga Sage
Giga Sage

JavaScript ES12 (also known as ECMAScript 2021) is a major update to the JavaScript language, bringing new features and capabilities for developers. Here is an overview of what you need to know about ES12 and its introduction within ServiceNow:

 

What is ECMAScript 2021/JavaScript ES12?

ECMAScript (often referred to as JavaScript) is a programming language standardized by the European Computer Manufacturers Association (ECMA). JavaScript ES12 is a standardized version of JavaScript that includes a number of new features and improvements over the previous versions1. You can find a complete list of the new features in ES12 in the official specification. However, not all ES12 are Supported by ServiceNow. Some are Not supported, where others are Disallowed. The list of all Supported, Not Supported, and Disallowed ES functionalities can be found here.

 

Client-side: This is the layer that runs in the user's web browser and is responsible for rendering the user interface and handling user interactions. This layer is implemented using JavaScript.

Server-side: This is the layer that runs on the ServiceNow server and is responsible for processing requests and performing tasks such as data manipulation and integration with external systems. This layer is implemented using Java, however, to ServiceNow developers the scripts are written in JavaScript using the Now Platform programming model. The Rhino JavaScript engine converts it to Java.

Willem_0-1671448557400.png

Global scope: This is the top-level scope in ServiceNow, which is shared by all scoped apps and other components of the platform.

Custom scope/Scoped app: This is a custom application created by developers using the ServiceNow platform. Scoped apps can be developed using a variety of tools and technologies, including JavaScript.

Willem_1-1671448557403.png

 

JavaScript library: This is a collection of functions and features that are specific to JavaScript and can be used to perform various tasks. ServiceNow includes a specific JavaScript library for use in the Global scope, and scoped apps, which includes functions and features that are specific to the ServiceNow platform.

Java library: This is a collection of functions and features that are specific to Java and can be used to perform various tasks. ServiceNow includes a Java library that is used by the server-side layer to perform tasks such as data manipulation and integration with external systems.

 

Brief overview of the history

Version

Description

ECMAScript 1 (1997)  This was the first version of ECMAScript, which was based on JavaScript 1.1.
ECMAScript 2 (1998)  This version made minor changes to the language to align it with the ISO/IEC 16262 international standard.
ECMAScript 3 (1999)  This version added regular expressions, try-catch statements, and other features to the language.
ECMAScript 4 (abandoned)  This version was intended to be a major update to the language, but it was eventually abandoned due to controversy and lack of support.
ECMAScript 5 (2009)  This version added support for strict mode, JSON parsing, and other features.
ECMAScript 6 (2015)  Also known as ECMAScript 2015, this version introduced significant changes to the language, including classes, modules, and arrow functions.
ECMAScript 7 (2016)  This version added support for Exponentiation operator, and Array.prototype.includes.
ECMAScript 8 (2017)  Also known as ECMAScript 2017, this version introduced Object static methods, String padding, and Trailing commas in function syntax.
ECMAScript 9 (2018)  This version introduced rest/spread properties and other features.
ECMAScript 10 (2019)  Also known as ECMAScript 2019, this version introduced the Array.prototype.flat() and Array.prototype.flatMap() methods, as well as the trimStart() and trimEnd() methods for strings.
ECMAScript 11 (2020)  This version introduced the String.prototype.matchAll() method, Optional chaining operators and other features.
ECMAScript 12 (2021)  This version introduced Logical assignment, Numeric separators and other features.
Willem_2-1671450668416.png

 

In addition to these official versions of ECMAScript, ServiceNow has also supported the use of Rhino, an open-source JavaScript engine developed by the Mozilla Foundation. Rhino was originally released in 1997 and has undergone several updates over the years. The use of Rhino can hinder the use of the latest versions of JavaScript server-side. Rhino may not always support the latest features of JavaScript, and it may take some time for new features to be fully supported in ServiceNow.

Willem_0-1671450613706.png

 

Why is ES12 important?

ES12 is important because it brings new capabilities to JavaScript that can help developers write more efficient, maintainable, and flexible code. By using the latest version of the language, developers can take advantage of the latest programming techniques and best practices. This can help improve the performance, reliability, and scalability of ServiceNow applications, leading to better user experiences and more successful projects.

Benefits to developers:

  • Shorter, easier to read code: ES12 introduces new syntax that can make it easier and more convenient to write code. For example, the ?. operator allows developers to safely access properties of an object without having to check if the object is null or undefined.
  • More maintainable: ES12 can help make code more maintainable by reducing complexity, improving performance, and providing more powerful and convenient ways to manipulate objects and strings.
  • More flexible: it is easier to add or modify in the ES12 version. ES12 includes new methods for manipulating objects, such as the Object.fromEntries() (ES10) and Object.values() (ES8) methods, which can make it easier to work with objects.

Benefits to business:

  • Improved performance and efficiency: the use of modern programming techniques can help improve the overall performance and efficiency of ServiceNow applications.
  • Faster development times: cleaner, more maintainable code can lead to faster development times.
  • Lower maintenance costs: more maintainable code can also lead to lower maintenance costs over the long term.
  • Improved user experience: the use of modern programming techniques can help improve the overall user experience of ServiceNow applications.
  • Improved reliability and scalability: the use of modern programming techniques can also help improve the reliability and scalability of ServiceNow applications.

 

What can you do with ES12 in ServiceNow?

ServiceNow has supported JavaScript ES12 since the Tokyo release in 2021. This means that developers can use the new features and capabilities of ES12 when customizing and extending the ServiceNow platform. Developers were already able to do so on the client-side, as there the available JavaScript version is dependent on browser support. However, with Tokyo, developers can now also use ES12 in Scoped apps on the server.

Prior to Tokyo:

Willem_4-1671448557408.png

As of Tokyo release:

Willem_5-1671448557410.png

For more information and examples of using ES12 in ServiceNow, I am working on providing explanations and examples for Supported features. As this is a work in progress the list will extend.

 

I hope this overview of ES12 and its introduction within ServiceNow has been helpful. If you have any further questions, please don't hesitate to ask.

Comments
CJB
Tera Expert

Thank you for this information. I was trying to figure out where/when I could use ES12.

Jamison Cote1
Tera Contributor

I am seeing ES12 as an option now on the latest Xanadu release.

 

But for Scripted REST API's.

 

Definitely a step in the right direction.

Version history
Last update:
‎12-19-2022 11:31 AM
Updated by:
Contributors