GlideAjax, GlideUser & GlideDialogWindow in ServiceNow
In the last topic, we learned how GlideForm and GlideList control forms and lists. A client script may need data from the server, details about the logged-in user, or a pop-up window to talk to the user.
In this topic, we will learn how GlideAjax supports client-server communication in ServiceNow, how GlideUser provides user information, and how to display dialog windows using GlideModal.
What is GlideAjax?
GlideAjax in ServiceNow is a client-side API that allows a client script to call server-side code stored in a Script Include. It is useful when a form needs information that is not already available in the browser.
For example, when a user selects a caller on an Incident form, you may want to retrieve the caller’s manager and display it automatically. GlideAjax can request this information from the server without reloading the form.
How GlideAjax Works?
It lets client scripts communicate with the server asynchronously (behind the scenes) without requiring a full form or page reload. One part runs in the browser (the client script), and one runs on the server (the Script Include). GlideAjax follows a simple process:
- A client script creates a GlideAjax object and specifies the Script Include name.
- It sends the method name and any required parameters.
- The Script Include runs on the server and processes the request.
- The server returns the result.
- The client script uses the returned data to update the form.
This process makes client-server communication in ServiceNow easier without requiring a full page reload. The official documentation recommends asynchronous methods such as getXML() or getXMLAnswer() instead of getXMLWait().
Note : Avoid synchronous calls like getXMLWait(), as they freeze the user’s browser until the server responds, leading to a poor user experience.
Let’s understand this process with a practical GlideAjax example ServiceNow.
Requirement: Fetch the caller’s manager using a Script Include.
Client Script (onChange):
var ga = new GlideAjax(‘CallerManagerAjax’);
ga.addParam(‘sysparm_name’, ‘getManager’);
ga.addParam(‘sysparm_caller_id’, newValue);
ga.getXMLAnswer(function(answer) {
g_form.setValue(‘u_caller_manager’, answer);
});
How it works: GlideAjax calls a client-callable Script Include to retrieve the manager’s ID and update the form.
What is GlideUser (g_user)?
GlideUser is a client-side API that provides information about the current user and their role. You use it through the g_user object, which is available automatically in client scripts.
You can use GlideUser to personalize messages, display user information, and check whether a user has a particular role.
For example, you can display a welcome message using the logged-in user’s first name or check whether the user has the ITIL role.
GlideUser Properties & Methods in Client-side scripting
The GlideUser API provides both properties and methods.
- Properties provide information about the current user.
- Methods perform checks or return information when called.
GlideUser Properties
| Properties | Purpose |
|---|---|
| g_user.firstName | Gets the user’s first name. |
| g_user.lastName | Gets the user’s last name. |
| g_user.userName | Gets the user’s login name. |
| g_user.userID | Gets the user’s unique sys_id. |
GlideUser Methods
| Method | Purpose |
|---|---|
| g_user.getFullName() | Returns the user’s full name. |
| g_user.hasRole(‘itil’) | Checks whether the logged-in user has a specified role or admin role. |
| g_user.hasRoleExactly(‘itil’) | Checks for the specified role without the special admin-role behavior of hasRole(). |
| g_user.hasRoleFromList(‘itil,admin’) | Checks whether the user has a role from a comma-separated list. |
| g_user.hasRoles() | Checks whether the user has roles other than the default public role. |
Note: These are client-side APIs. Their availability can vary by interface and scripting context, so check the API reference for your ServiceNow release.
What is GlideDialogWindow?
GlideDialogWindow is a client-side JavaScript API in ServiceNow used to display custom pop-up dialog windows (such as custom UI Pages) within the current browser window or frame.
It can be used to display additional information, collect input, or provide a separate interface without navigating away from the current page.
However, ServiceNow has deprecated GlideDialogWindow and recommends GlideModal for new development. GlideModal provides a modern way to display dialog windows and is a better choice for new examples.
Let’s understand with the GlideDialogWindow example ServiceNow:
Requirement: Open a dialog when a user clicks a button on an incident form.
ServiceNow recommends GlideModal for new development instead of the deprecated GlideDialogWindow.
Client-side UI Action:
function openHelpDialog() {
var dialog = new GlideModal('incident_help_dialog');
dialog.setTitle('Incident Help');
dialog.render();
}
How it works: When the user clicks the button, GlideModal opens the UI Page in a dialog without navigating away from the Incident form.
Practical Use Cases
Use Case 1: Check a user’s role before showing a field (GlideUser)
Only users with the ITIL or Maintain role should see the Close notes field.
function onLoad() {
if (!g_user.hasRoleFromList('itil, maint')) {
g_form.setDisplay('close_notes', false);
}
}
Use Case 2: Greet the user with their name (GlideUser)
function onLoad() {
if (g_form.isNewRecord()) {
g_form.addInfoMessage('Welcome, ' + g_user.firstName + '! Please fill in all the details.');
}
}
Use Case 3: Get server data when a field changes (GlideAjax)
This is the manager lookup from the GlideAjax example above. The same pattern works for any task that needs server data. Change the Script Include method and its parameters, and the client script stays almost the same.
Use Case 4: Show a dialog from a button (GlideDialogWindow / GlideModal)
Add this to the Client field of a UI Action. The button opens a dialog that loads your UI page.
function openDialog() {
var dialog = new GlideModal('my_dialog_page'); // your UI Page name
dialog.setTitle('Add a comment');
dialog.setPreference('sys_id', g_form.getUniqueValue());
dialog.render();
}
Conclusion
Client-side scripting is an important part of ServiceNow development. This chapter covers the basics of client-side scripting, including GlideForm and GlideList methods, and how GlideAjax, GlideUser, and GlideDialogWindow help developers build interactive forms. Together, these concepts help developers control form behavior, work with lists, retrieve server-side data, access user information, and display dialog windows.
In the next chapter, we will focus on server-side scripting in ServiceNow, where you will learn how to work with records, automate business processes, and interact with the database using server-side APIs.
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.