ServiceNow Client Script Interview Questions 2026
What is a Client Script, and what are the different types of Client Scripts?
A Client Script is a JavaScript code that runs on the client-side, typically in a user's web browser. It is triggered by specific client-side events, such as when a form is loaded, when a form is submitted, or when a field value is changed. Client Scripts allow you to enhance user interactions by executing custom logic in response to these events.
There are four main types of Client Scripts:
1. OnLoad: Executes when the form is loaded in the browser. It is commonly used to set default values, modify the form layout, or hide/show fields.
2. OnSubmit: Runs when the form is submitted. It is used to validate form data or perform additional actions before the form is saved.
3. OnCellEdit: Triggers when a cell in a record is edited (typically in list-type forms). It allows you to perform actions based on the changes made to the data in the cell.
4. OnChange: Activates when the value of a field changes. This script is useful for dynamically updating other fields, performing validation, or applying conditional logic based on the new value.
Can we execute an OnChange Client Script during form load? If so, how?
Yes, an OnChange Client Script is always triggered during form load. However, the script often includes a condition that prevents further execution of script if the form is in "loading" state. This is typically controlled by a variable like isLoading, which indicates whether the form is in the process of loading.
To execute the OnChange script during form load, you can modify the script to remove or adjust this check. Here's how you can achieve this:
1. Locate the condition that checks if the form is loading that is condition with isLoading variable.
2. Remove or modify this condition so that the OnChange logic is triggered regardless of the form's loading state.
Sample client script for reference:
How can you allow a user to update the incident state but restrict them from closing it in the list view? OR explain the OnCellEdit Client Script with a real-time use case.
Example Use Case:
In this scenario, we want to allow the user to update the incident state but prevent them from closing the incident directly through the list view (i.e., preventing the state from being set to "Closed").Below is an example client script which checks if new state value is closed, if yes then don't update the record by sending 'false' parameter to callback function which prevents record update else send 'true' to callback function which will update the record.
Solution
You can create an OnCellEdit Client Script on state field that checks if the new state value is "Closed." If the user tries to close the incident by changing the state to "Closed," the script will block the update. If the new state is anything other than "Closed," the record update will proceed as normal.
function onCellEdit(tableName, record, columnName, oldValue, newValue, callback) {
if (newValue === 'Closed') {
// Prevent update if the state is being set to "Closed"
callback(false); // Pass 'false' to prevent update
} else {
// Allow update if the state is not being set to "Closed"
callback(true); // Pass 'true' to allow update
}
}
Explaination
The script checks whether the new value is "Closed." If the state is being set to "Closed," the callback(false) prevents the record from being updated. If the state is not being set to "Closed," the callback(true) allows the record update to proceed.
What are the different ways to access server-side data in a Client Script?
1. Using the getReference() method:
This method is used to retrieve related record data from the server. It allows you to fetch reference field data asynchronously in a Client Script. For example, if you have a reference field in a form, you can use getReference() to fetch additional data related to that reference field.2. Using GlideAjax:
GlideAjax is a powerful way to call Script Includes from a Client Script. It allows you to send data to the server and retrieve the result asynchronously. This method is useful when you need to perform complex server-side logic or access large sets of data that cannot be efficiently handled directly on the client-side.3. Using display Business Rule (BR):
A Display Business Rule can be used to execute server-side logic and return data to the client-side when a form is loaded. This is useful when you want to perform server-side actions, such as data population or validations, during form load phase.Note:
While it is technically possible to use the GlideRecord API directly in Client Scripts to query server-side data, this is not recommended by ServiceNow. Using GlideRecord in Client Scripts can impact performance and may lead to issues with health scan reports, as it bypasses the platform's recommended data access patterns for client-side scripts.In summary, for accessing server-side data, the best practice is to use getReference(), GlideAjax, or a Display Business Rule, as these methods are optimized for client-server communication and adhere to ServiceNow's best practices.
What is the order of execution between UI Policies and Client Scripts?
If there is conflicting logic between a Client Script and a UI Policy, the logic defined in the UI Policy takes precedence and is applied. In cases where both are used to manipulate the same field or form behavior, it's important to carefully plan the logic to avoid conflicts and ensure the desired outcome.
What are the different ways to make field mandatory?
In ServiceNow, there are several ways to make a field mandatory, each with its own use case:
1. Client Script
You can use a Client Script (specifically, an onChange or onSubmit Client Script) to dynamically set a field as mandatory based on certain conditions. This allows for client-side validation and flexibility in how and when the field becomes mandatory.
2. UI Policy
UI Policies can be used to make fields mandatory based on form interactions or conditions. UI Policies are easier to manage than Client Scripts for simple use cases and automatically update the form when conditions are met.
3.Data Policy
Data Policies are similar to UI Policies but are designed to enforce field rules at both the client and server levels. These are particularly useful for ensuring data consistency across records, regardless of how the data is being submitted (e.g., via the UI, API, or import sets).
4.Field Dictionary Level
You can set a field as mandatory at the dictionary level, which ensures that the field is always required whenever a record is created or updated, regardless of the context in which it is used. This is a permanent, system-wide setting for the field.
Each of these methods can be used independently or together, depending on your requirements for field validation and business logic.
1. Client Script
You can use a Client Script (specifically, an onChange or onSubmit Client Script) to dynamically set a field as mandatory based on certain conditions. This allows for client-side validation and flexibility in how and when the field becomes mandatory.2. UI Policy
UI Policies can be used to make fields mandatory based on form interactions or conditions. UI Policies are easier to manage than Client Scripts for simple use cases and automatically update the form when conditions are met.3.Data Policy
Data Policies are similar to UI Policies but are designed to enforce field rules at both the client and server levels. These are particularly useful for ensuring data consistency across records, regardless of how the data is being submitted (e.g., via the UI, API, or import sets).4.Field Dictionary Level
You can set a field as mandatory at the dictionary level, which ensures that the field is always required whenever a record is created or updated, regardless of the context in which it is used. This is a permanent, system-wide setting for the field.Each of these methods can be used independently or together, depending on your requirements for field validation and business logic.
What is the purpose of the "Isolate Script" checkbox in Client Scripts?
If you want the Client Script to perform DOM manipulation, you should uncheck this checkbox. This allows the script to execute JavaScript that interacts with HTML elements, such as displaying alerts or modifying page elements dynamically.
DOM Manipulation Code Example
alert("Test message");
document.getElementById("elementId").style.color = "red";
Note:
DOM manipulation refers to any JavaScript code that interacts with HTML elements on the page, such as changing styles, displaying popups, or accessing form fields directly. However, DOM manipulation is generally not recommended as a best practice in ServiceNow Client Scripts. It can lead to performance issues, inconsistencies across browsers, and challenges with maintainability.
How to access dot walked field value in Client Script?
There are few fields which are not part of current table, they are brought from another reference field table.
e.g. In below example, highlighted field is Caller Email which is brought from Caller reference that is from USER table.

So, to access value from such field, we can use below syntax in client script:
g_form.getValue("caller_id.email");
Which all client script gets executed when we change field value via a list view?
You might expect that OnChange or OnSubmit Client Scripts would also execute when a field is updated, as they typically run when a field value is changed or a form is submitted. However, OnChange and OnSubmit Client Scripts are designed to run on forms, not in list views. Therefore, they do not execute when a field is updated in a list view.
When should we use a Client Script versus a UI Policy?
UI Policies are ideal for scenarios where you need to make fields mandatory, read-only, or conditionally hide/show fields based on certain conditions. They offer an easy way to enforce field behaviors without writing complex scripts.
Client Scripts, on the other hand, are more versatile and allow you to write advanced scripting logic. They are suitable for tasks like dynamically setting form field values based on complex conditions, retrieving server-side data on the client-side, or performing other custom client-side processing.
What is the g_form object in ServiceNow, and can you provide five common methods of the g_form object along with their usage?
Here are five common methods of the g_form object and their usage:
1. g_form.setValue(fieldName, value)
Sets the specified field's value to the given value.Usage: To programmatically set a field value on the form.
Example: g_form.setValue('priority', 2);
2. getValue(fieldName)
Retrieves the current value of a specified field.Usage: To get the value of a field on the form. Example: var priorityValue = g_form.getValue('priority');
3. g_form.addInfoMessage(message)
Displays an informational message at the top of the form.Usage: To show a non-intrusive informational message to the user. Example: g_form.addInfoMessage('Your changes have been saved successfully.');
4. g_form.showFieldMsg(fieldName, message, type)
Displays a message on a specific field. The message can be informational, error, or warning. Usage: To display a message next to a specific field, often used for validation or instructional messages. Example: g_form.showFieldMsg('short_description', 'Please enter a valid description.', 'error');5. g_form.addOption(fieldName, choiceValue, choiceLabel)
Adds a new option to a choice list field. Usage: To dynamically add a new option to a choice field (e.g., drop-down menu). Example: g_form.addOption('category', 'new_option', 'New Category');
How can we prevent form submission using client script?
We can prevent form submission by using the "return false" statement in an "onSubmit" client script. This method is typically used to validate the form before allowing submission.
Here is an example client script:
function onSubmit() {
// Custom validation logic
if (g_form.getValue('some_field') == '') {
alert('Some field must be filled!');
return false; // Prevent form submission
}
// If validation passes, the form will submit normally
return true;
}
How to execute a client script for a specific view? What does the 'Global' checkbox mean in a Client Script?
When we uncheck the 'Global' checkbox, a new field labeled 'View' becomes available. In this field, we can specify the name of the view for which we want the client script to execute. This allows us to tailor the behavior of the script for different views, ensuring that the script runs only when needed.
Which all objects we can access in client script?
In client scripts, we can access the following key objects to interact with the form and user data:
1. g_form: This object is used to interact with form fields, retrieve or set field values, manipulate field visibility, read-only status, and other form-related properties.
e.g. g_form.setValue('field_name', 'new_value');
2. g_scratchpad: This object is used to store temporary data on the client side that can be passed from server-side scripts (like Business Rules or Script Includes) to the client-side. It is useful for sharing data between server and client without modifying the form fields.
e.g. g_scratchpad.someData = 'value from server-side script';
3. g_user: This object provides information about the currently logged-in user, such as their username, roles, and other user-related data. It's helpful for conditionally controlling the behavior of client scripts based on the user's identity or role.
e.g. var currentUser= g_user.getUsername();
Real Time Sample Questions:
1. Explain any complex client script that you have created for given requirement?
2. Did you learn anything interesting while working on client script which is not common or documented?
3. Did you ever face any issue/challenges while using GlideAjax call in client script?
4. If you used GlideAjax method to get server side data then why used GlideAjax, why not getReference or Display BR?
Assignment for you:
1. How to send more than one variable from server side script to client side while using GlideAjax?
2. Why we won't be able to stop form submission while validating form data via GlideAjax call?
3. Explain each step that needs to be done on script include side to use it for GlideAjax?
Most candidates who fail weren't underskilled.
They were underprepared.
These free questions cover the basics. But interviews go deeper. Discovery, ITOM, SecOps, Flow Designer, Now Assist, AI Agents. The Job Switch Kit gives you the full 15-day roadmap, 500+ structured Q&A across every module, a LinkedIn profile optimisation guide so recruiters find you before you even apply, and an interview bot that practices with you until you're ready. Most candidates walk in under-prepared. Don't be one of them.
Battle-tested questions with structured answers across every high-frequency topic — ITOM, SecOps Vulnerability Response, Discovery, Flow Designer, AI Agents, Generative AI, and Now Assist. Plus a dedicated Behavioral round covering HR questions, STAR method answers, salary negotiation, and career direction — because technical prep alone is not enough to get the offer
Day-by-day curriculum in the right order — scripting fundamentals, ITSM & CMDB, integrations, AI modules, and behavioral prep — so you peak exactly on interview day
Two modes: system-guided sessions with curated ServiceNow questions, and self-practice where you bring your own questions. Every session is recorded — download your Q&A transcript, review your answers, and pinpoint exactly where you need to improve
Proven strategies for counter-offers, CTC decoding & in-hand salary strategy
Notice period tactics, BGV prep, resignation playbook & offer comparison
Track completion per topic, rate your confidence per question, add private notes at question level and page level. Only you see them. Always know exactly what to tackle next
Step-by-step guide to rank in recruiter searches before you apply. Module-specific keyword lists, role-based headline and About section templates, experience bullet formulas, and certification display guidance built specifically for ServiceNow professionals
🔒 Secure payment via Razorpay · Instant access after payment
Your story could be the reason someone else lands their next ServiceNow role
If this content made a real difference in your prep, sharing that experience with your network helps other professionals discover it — and we'd love to say thank you with 10 days of premium access, completely on us.
Real Interview Questions & Answers
Questions shared by ServiceNow professionals and reviewed for clarity, relevance, and interview usefulness.
Share real interview questions and help the ServiceNow community prepare better. All submissions are reviewed before publishing.
🚀 Power Up Your ServiceNow Career
Join a growing community of smart ServiceNow professionals to stay ahead in interviews, sharpen your development skills, and accelerate your career.
Login to leave a comment or feedback. Your voice helps improve the content for everyone.