ServiceNow Java Script
ServiceNow Java Script is a scripting language that enhances the functionality of the service management platform. It helps in enabling the creation of different applications, generating source codes and many more.
Using Java Script, ServiceNow developers can perform various operations like creating database operations without writing out SQL queries, add information messages or configure buttons and customize CRUD operations.
Scripting in ServiceNow
Scripting is an extremely powerful way to configure ServiceNow, and the right way to write your scripts will depend on many different factors. This includes how often they run and how much data they need to access.
The types of scripts that you can write in ServiceNow fall into two categories: client-side and server-side. These are the kinds of scripts that run in the browser and interact with the user’s screen, or on the server and are used to gather data from the database.
You can use either type of script in ServiceNow, depending on your needs. For instance, a business rule is a server-side script that runs once a form is submitted, and it can use all of the information in the database instead of just what is loaded on the web page.
However, this can result in a slight delay as the information is gathered on the server, which is why it’s best to avoid using a client-side script that calls a server-side script. This is especially true for GlideRecord queries, which can have a performance impact when they are called from the client.
Glide API
The Glide API allows you to work with ServiceNow tables in scripts without writing SQL queries. You can use Glide classes to perform database operations, display UI pages, and define UI actions.
For example, you can create a script that populates a message in a form field if a particular assignment group is selected. Or, you can create a script that triggers a business rule when the description field value changes.
The Glide API provides methods to query, insert, update, and delete records in your database. These methods are often used to build business rules, UI actions, and scheduled job scripts in ServiceNow. They are also useful for customizing the user experience, and they allow you to add informational messages or configure buttons. These methods are available in both client and server versions of ServiceNow. You can find more information about the Glide API in the official ServiceNow documentation.
UI Policies
ServiceNow Java Script works by modifying and controlling the behavior of information on a form. These controls are implemented through UI Policies and UI Actions.
UI Policy actions are buttons, links, and context menus that contain interactive scripts for custom functionality. These can be placed on a form or list and run automatically when the form is loaded or when a condition changes.
A UI Policy can be view-specific or global. If the Global option is selected, the UI Policy applies to all form views.
The UI Policy Order field specifies which UI Policy executes first. If you have a UI Policy with a higher Order value than another UI Policy, the higher-order policy runs first.
UI Policies are executed on the client, while Data Policies are executed on the server. This means that UI Policies are not as effective at preventing changes from being made to the database as Data Policies are. However, they can still be useful.
UI Actions
UI Actions are a way to add buttons, links, and context menu items to forms and lists. This makes the UI more interactive, customizable, and specific to user activities.
You can use UI Actions for things like adding a create problem button to an existing incident form, or a related link at the bottom of a list. UI Actions can also be used to make “real-time” changes to the appearance of forms, especially when it comes to UI pages and UI macros.
Most of the time UI Actions are server-side, but they can also be client-side when you define them with the ‘Client’ checkbox selected. This allows you to perform some client-side JavaScript, including checking mandatory fields, when the UI Action is called.