Server-Side and Client-Side Scripting
Server-Side and Client-Side Scripting
Server-Side Scripting
1. What is the difference between GlideRecord and GlideAggregate? When would you
use each?
Example:
Example:
Use Case: When you need aggregate data, such as the count of records matching
a condition.
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 1/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
if (!gs.getSession().get('business_rule_run')) {
gs.getSession().put('business_rule_run', true); // Your business rule logic
here } else { return; }
3. Write a script to get the number of open incidents assigned to the current user.
4. What is a Script Include? How do you make it accessible from the client side?
A Script Include is a reusable server-side script. To make it accessible from the client side,
you can use GlideAjax.
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 2/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
Before: Runs before the record is saved. This is useful for validating or modifying
record data before it is committed to the database.
After: Runs after the record is saved. This is useful for performing additional actions,
such as notifications or related record updates.
Async: Runs asynchronously after the record is saved, often used for non-blocking
tasks such as calling an external API or updating other systems.
current: Refers to the current state of the record being processed by the Business
Rule.
previous: Refers to the state of the record before the update was made. It is useful for
comparing changes (e.g., current.priority != previous.priority ).
7. How would you find the first 5 users who logged in today using GlideRecord?
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 3/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
10. How do you call one Script Include from another Script Include?
You can call a Script Include directly in another Script Include by creating an instance of
the class.
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 4/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
Client-Side Scripting
1. What are the types of Client Scripts in ServiceNow? Explain with use cases.
onLoad: Executes when a record is loaded. Useful for setting default values or UI logic.
onChange: Executes when a field’s value changes. Useful for dynamic form updates
based on user input.
onSubmit: Executes when the form is submitted. Useful for validation before saving a
record.
Client Script: Sends a request via GlideAjax to call the Script Include.
Script Include: Receives the request, processes it, and returns the result.
4. How do you hide a field based on the value of another field using a Client Script?
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 5/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
javascript Copy Edit
I’ll continue the rest of the questions in the next response! Would you like me to continue,
or would you prefer a break before the next section?
Great! Let me continue with the remaining answers and then generate the PDF for you.
5. Write a Client Script to validate if the caller is from the same department as the
logged-in user.
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 6/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
Example:
GlideRecord: Used to query any table in ServiceNow. It's a powerful object used for
CRUD operations.
Example:
7. What’s the purpose of g_scratchpad and where would you use it?
g_scratchpad is used to pass data between the server and client script. It's commonly used
in UI Scripts and Business Rules to temporarily hold and share data between server-side
and client-side code.
Example (Server-side):
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 7/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
g_scratchpad.user_name = gs.getUser().name;
Example (Client-side):
alert(g_scratchpad.user_name);
8. How can you make a reference field mandatory only when another field is
selected?
onLoad: Executes when the form is loaded. Use it to set default field values, UI
changes, or logic when the form is first presented.
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 8/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
Example:
1. You need to prevent non-admin users from seeing VIP caller records. How would
you approach this?
You can create an Access Control Rule (ACL) for the VIP field on the Incident table. For
non-admin users, you can restrict access to that field by checking if the user has admin
privileges.
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 9/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
Verify the State of the record (it may not trigger if the record is in a state that doesn’t
require approval).
3. How do you ensure that only one open incident exists per user at a time?
You can use a Before Business Rule to check if the user already has an open incident.
4. You’ve written a Business Rule to update a field, but it’s not working. What steps
would you take to debug it?
5. Explain how you would calculate average resolution time for incidents and display
it on a dashboard.
Create a Scheduled Script that calculates the average resolution time and stores it in a
custom table or a report.
Example:
javascript
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 10/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
Copy Edit
var gr = new GlideRecord('incident'); gr.addQuery('state', 'Closed');
gr.query(); var totalResolutionTime = 0; var count = 0; while (gr.next()) {
totalResolutionTime += gr.resolution_time; // Assuming it's stored in seconds
count++; } var avgResolutionTime = totalResolutionTime / count;
gs.info('Average Resolution Time: ' + avgResolutionTime);
6. A user says their catalog item isn't visible to them. How would you troubleshoot
this?
Check the User’s Roles to ensure they have access to that catalog.
You can create a Scheduled Job and set the schedule to run weekly on Sunday at 2 AM.
8. What’s the use of the Display Business Rule, and when would you use it?
The Display Business Rule runs when a record is loaded and is used to set values on the
client-side form before rendering it in the UI. It’s helpful for scenarios where you need to
manipulate fields or data for display but not save it to the database.
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 11/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
Use Update Sets to capture configuration changes (e.g., Business Rules, Tables, ACLs).
10. Explain how ACLs work and how to troubleshoot access issues.
Access Control Rules (ACLs) define who can access a resource (like records or fields). You
can troubleshoot access issues by:
Script Include:
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 12/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
javascript Copy Edit
Client Script:
4. Client Script to restrict closing an incident unless resolution notes are filled.
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 13/14
6/28/25, 9:45 PM Server-Side and Client-Side Scripting
https://chatgpt.com/c/68601348-b92c-800e-be81-a31f4709d9b9 14/14