ServiceNow Java Script
Java Script is a scripting language that can be used to create customised applications and modules. It enables users to modify UI, process flow and business rules without needing to compile them.
The ServiceNow platform uses JavaScript to run its applications. Hence, it is important to understand how to use JavaScript in ServiceNow to get the most out of it.
UI Policies
ServiceNow Java Script policies allow you to control the behavior of form information. For example, you can make a field mandatory or read-only based on some condition or load.
A UI policy can be view-specific, which means that it only applies to one form view. You can set the option for this in the UI policy settings.
You can also create global UI policies, which apply to all form views. This can help you avoid the need to write client-side scripts for each form view.
You can also use JavaScript to add logging to the ServiceNow platform. Unlike GlideSystem logging methods, which send logs to a window at the bottom of the screen, a JavaScript logger window displays logs in a more user-friendly format.
UI Actions
ServiceNow UI actions are a group of scripting elements that can show up on forms and lists as buttons, links, or context menu items. They execute client-side JavaScript when they’re clicked.
These scripts help make a form more interactive, customised, and specific to user activities. They allow users to configure forms and lists with informational messages, add custom button configurations, and customize CRUD operations.
UI Actions are one of the most commonly used features by ServiceNow Admins and Consultants. They can be configured to do things like validate input and check for mandatory fields, as well as set field attributes such as the impact or priority values.
UI Actions are written in a client-side scripting language called JavaScript, which is a subset of the larger Java programming language. This means that they are executed only when the client browser is open, not when the underlying backend platform is running (a bad practice).
Client-Side Scripting
Client-side scripting runs in the user’s web browser, rather than on the server (on the ServiceNow application server or database). This saves time by reducing round trips.
Typically, client-side scripts are used for immediate form changes, form validation or limited database lookups. They can also be used to provide more user-friendly forms, including popup alerts and dropdown lists.
The ServiceNow Java Script client-side API provides classes and methods that you can use in your scripts. However, understand the limitations of your environment and use these APIs wisely.
The JavaScript API can be used to create a variety of different types of client-side scripts. These include UI actions, UI policies and UI policy actions, and catalog Client Scripts.
Server-Side Scripting
Server-side scripting uses a computer program to execute code on the server that delivers a customized response to each client request. It is a popular choice for web development.
Several types of scripts are available in ServiceNow that can be used to customize the user interface, including UI macros and processors. Processors allow administrators to create a customizable URL endpoint that can be used to run arbitrary server-side JavaScript code and produce output such as TEXT or JSON.
Business rules are a type of server-side script that runs when a record is displayed, inserted, updated, deleted, or when a table is queried. These scripts can be configured to perform various tasks, such as amending field values, or updating parent and child records.
These scripts can be stored in a database or a web page, and can also be called by other server-side JavaScript programs when appropriate. They can also be grouped into categories, such as UI Actions or Script Include, and they can be written in a variety of languages.