3

ServiceNow Client-Side Scripting Basics

Client-side scripting in ServiceNow helps you control how forms behave when users interact with them. You can use it to show or hide fields, validate information, display messages, and update values instantly. In this topic, we will focus on what client-side scripting is, where to use it, and the client-side Glide classes and APIs that you will use most often in ServiceNow.

What is client side scripting?

Client Scripts are pieces of JavaScript code that run on the client side (the user’s web browser) rather than the server (the ServiceNow database). They respond to user actions and make changes immediately, without always needing to contact the server.

The primary purpose of using it:

  • Responds to user actions: Runs when a user opens a form, changes a field, or clicks Save.
  • Provides instant feedback: Displays messages and updates form fields immediately.
  • Improves user experience: Makes forms more interactive and user-friendly.

Where to use it?

If you want to know where to use client-side scripting in ServiceNow, the platform provides several options depending on your goals.

  • Client Scripts: run on forms and lists (OnLoad, OnChange, OnSubmit, OnCellEdit).
  • Catalog Client Scripts: work the same way, but on Service Catalog items and variables.
  • UI Policy scripts: the “Execute if true/false” scripts, for conditions that need more than the standard options.
  • Client-side UI Actions: buttons and links that run browser code when clicked.
  • UI Scripts: reusable client-side JavaScript libraries that other client scripts can call.

Client-side Glide class

A client-side Glide class in ServiceNow provides ready-made methods that help developers work with forms, user information, and server-side data.

These classes save time because you do not need to write every function from scratch. They provide methods for common tasks, such as setting field values, displaying messages, checking user roles, and retrieving information from the server.

Here are three important client-side Glide classes:

GlideForm (g_form)

GlideForm is the class you will use most. You don’t need to create it, because ServiceNow makes g_form available automatically in client scripts. It controls how a form looks and behaves.

GlideUser (g_user)

GlideUser tells you who is working on the form right now. It is also available automatically as g_user. You can check the user’s name or ID, or find out whether they have a particular role. This is useful for scripts like “hide this field unless the user is an admin.”

GlideAjax

Sometimes a client script needs data that only the server has. GlideAjax solves this by calling a client-callable script included in the background. The call is asynchronous, so the form stays usable while the server works. Unlike g_form and g_user, you create a GlideAjax object yourself.

Client-Side Glide Class Object Used What It Does
GlideForm g_form Customizes forms: reads and sets values, shows messages, controls how fields behave.
GlideUser g_user Gives information about the logged-in user and their roles.
GlideAjax new GlideAjax() Lets a client script run server-side code (a Script Include) without reloading the page.

Note – Other client-side classes exist for specific needs, such as GlideList2 (g_list for lists), GlideModal and GlideDialogWindow (pop-up dialogs), and GlideModalForm (a form inside a pop-up).

Client-Side APIs 

An API is a set of ready-made methods you can call in your script. A client-side API in ServiceNow is a collection of ready-made methods that developers can use to control form behavior, access user information, and perform other browser-side tasks.

These APIs help developers build interactive forms without writing all the functionality from scratch. Common examples include:

  • GlideForm API: Uses g_form to manage form fields, values, and messages.
  • GlideUser API: Uses g_user to access information about the current user.

What’s Next? 

Sometimes a client script needs to change how the form looks or behaves, or work with the records in a list. This is done with the help of GlideForm and GlideList. In the next topic, we will understand GlideForm and GlideList in ServiceNow through a practical Client Script guide.

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.

SALE IS LIVE
50% OFF