1

What is Scripting in ServiceNow?

Servicenow is a low-code platform that allows you to create forms, flows, and configuration without needing a deep understanding of code. However, there are times when businesses need logic that is not present in the out-of-the-box settings. This is where scripting comes in. 

Starting with the ServiceNow developer tutorials, let us start by understanding what scripting is, when and where to use it, and what its different types are. 

What is scripting in ServiceNow?

ServiceNow uses its own JavaScript Engine (Rhino) to control how the platform operates. Scripts are used to perform CRUD operations, data validation, and write log files. It helps auto-populate fields, hide or show form sections, send notifications, and integrate with third-party applications. 

With scripting in ServiceNow, it is important for you to understand when and where to use it and what its different types are.

When to use scripting in ServiceNow?

There are many instances where you might feel the urge to use scripts, but remember it should not be your first choice. You only use them when they might add value, as wrong scripts can make your system slow and hard to maintain. The major functionality that requires scripting is: 

  • To set one field based on another field. 
  • To create new records based on the client- and server-side action. 
  • To set a field value on a record that can’t be added directly from the event-triggering record. 
  • To validate the field content on the client side. 

Where to use Scripting in ServiceNow? 

ServiceNow scripts can be written in different places on the platform, including: 

  • Business rules
  • Client Scripts
  • Script includes
  • UI actions
  • Scheduled Jobs
  • Flow Designer and workflow
  • Scripted REST APIs
  • Notifications and Email Script
  • Fix scripts and background scripts

These are some of the places where you can add custom scripts to run logic, control user behavior, store functions, add buttons, create custom endpoints, and run quick tests. 

Types of scripting

Scripting in serviceNow is divided into two types based on where the code is running. This includes: 

Server-side scripting

Server-side scripts run on the ServiceNow instance in the application. Here, developers get access to the database via Glide APIs for processing, security and automation. It is used in business rules, script includes, scheduled jobs, fix scripts, scripted REST APIs, and server-side UI actions. 

Server-side scripting is best for adding business logic, updating related records, integrations, and ensuring that the flows run regardless of changes in records. 

Client-side scripting

Client-side scripting runs directly on the user’s web browser. It is used to respond instantly to what users do on the screen, without any round trip to the servers. It works on Client Scripts, Catalog Client Scripts, UI Scripts and Client-side UI Actions.

Client-side scripting is best for enhancing the user experience, showing or hiding fields, making fields compulsory, and for instant feedback. Also, the Client-side checks are for user experience only and can be bypassed.

What’s Next? 

Sometimes client scripts need server data, which is done with the help of GlideAjax. In the next topic, we will understand the Glide classes and script execution engine. 

Next Topic

Need more support?

Get a head start with our FREE study notes!

Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.