A Script Include is basically a reusable server-side JavaScript class in ServiceNow.
- It contains functions (methods) that you can call from other server-side scripts (like Business Rules, Background Scripts, Workflow Scripts, etc.).
- Think of it as a utility/helper library for your ServiceNow code.
Example
Suppose you need to get the caller’s email address from an Incident record.
Instead of writing the same GlideRecord query everywhere, you put it in a Script Include:
When to use it?
- In Background Scripts for testing incident information.
- Inside Business Rules to automatically get caller or priority.
- In Workflows / Flow Designer to check incident fields quickly.
- Whenever the same incident logic is required in many places.
Why do we use it?
- To avoid writing GlideRecord queries again and again.
- To make code smaller and reusable.
- To keep all incident-related logic in one place.
- Easy to maintain and extend later.
- Assignment 1 – UserUtil , inlude many functions like getFirstName, getLastName, getDepartment etc at least add 10 functions.
What is User Util ?
UserUtil is a Script Include created in ServiceNow to keep user-related helper functions at one place. It helps in fetching data like name, email, phone, department, etc., from the sys_user table.
When to use it ?
- Whenever a script needs user details again and again.
- In background scripts for testing user info.
- Inside business rules or workflows where user data is required.
Why do we use it ?
- Saves time (no need to repeat GlideRecord queries).
- Makes code easy to read and maintain.
- Keeps all user utility functions in a single place.
- Reusable across different scripts.
Steps to Create UserUtil
1. Open Script Includes
- Go to System Definition → Script Includes and click on New

- Fill Details
- Name: QAUserUtil
- Active: ✅
- Accessible from: All application scopes
- Client Callable: ❌

- Add Script Code
- var QAUserUtil = Class.create();
- QAUserUtil.prototype = {
- initialize: function() {},
- // Function 1: Get User Email
- getUserEmail: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getValue(’email’);
- }
- return ”;
- },
- // Function 2: Get User ID (user_name / login name)
- getUserID: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getValue(‘user_name’);
- }
- return ”;
- },
- // Function 3: Get First Name
- getFirstName: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getValue(‘first_name’);
- }
- return ”;
- },
- // Function 4: Get Last Name
- getLastName: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getValue(‘last_name’);
- }
- return ”;
- },
- // Function 5: Get Department
- getDepartment: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getDisplayValue(‘department’);
- }
- return ”;
- },
- // Function 6: Get Manager
- getManager: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getDisplayValue(‘manager’);
- }
- return ”;
- },
- // Function 7: Get Phone Number
- getPhone: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getValue(‘phone’);
- }
- return ”;
- },
- // Function 8: Get Mobile Number
- getMobile: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getValue(‘mobile_phone’);
- }
- return ”;
- },
- // Function 9: Get Location
- getLocation: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getDisplayValue(‘location’);
- }
- return ”;
- },
- // Function 10: Get Job Title
- getJobTitle: function(sysID) {
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’, sysID);
- user.query();
- if (user.next()) {
- return user.getValue(‘title’);
- }
- return ”;
- },
- //Function 11: Get the Time Zone
- getTimeZone: function(sysID){
- var user = new GlideRecord(‘sys_user’);
- user.addQuery(‘sys_id’,sysID);
- user.query();
- if(user.next()){
- return user.getValue(‘time_zone’);
- }
- return “”;
- },
- type: ‘QAUserUtil’
- };
- To check in Background Script
- var util = new QAUserUtil();
- var userSysId = ‘f7c5637b5369aa50c07456a0a0490eaa’;
- gs.info(“First Name: ” + util.getFirstName(userSysId));
- gs.info(“Last Name: ” + util.getLastName(userSysId));
- gs.info(“Email: ” + util.getUserEmail(userSysId));
- gs.info(“Department: ” + util.getDepartment(userSysId));
- gs.info(“Manager: ” + util.getManager(userSysId));
- gs.info(“Phone: ” + util.getPhone(userSysId));
- gs.info(“Mobile: ” + util.getMobile(userSysId));
- gs.info(“Location: ” + util.getLocation(userSysId));
- gs.info(“Job Title: ” + util.getJobTitle(userSysId));
- gs.info(“Location: ” + util.getLocation(userSysId));
- gs.info(“Job Title: ” + util.getJobTitle(userSysId));
- Output

- Assignment 2 – IncidetnUtil – create SI . getCaller(), getCallerLocation(), getPriority()
What is Incident Util ?
IncidentUtil is a Script Include made for the incident table in ServiceNow. It contains helper functions to fetch details like caller name, caller’s location, priority, state, and phone number of the caller.
When to use it?
- In Background Scripts for testing incident information.
- Inside Business Rules to automatically get caller or priority.
- In Workflows / Flow Designer to check incident fields quickly.
- Whenever the same incident logic is required in many places.
Why do we use it?
- To avoid writing GlideRecord queries again and again.
- To make code smaller and reusable.
- To keep all incident-related logic in one place.
- Easy to maintain and extend later.
Steps to Create IncidentUtil
- Open Script Includes
- Navigate to System Definition → Script Includes and click New.

- Fill Form Details
- Name: QAIncidentUtil
- Active: ✅ Yes
- Accessible from: All application scopes
- Client Callable: ❌ No
- Add Script Code

var QAIncidetnUtil = Class.create();
QAIncidetnUtil.prototype = {
initialize: function() {},
getCaller: function(incSysId) {
var inc = new GlideRecord(‘incident’);
inc.addQuery(‘sys_id’, incSysId);
inc.query();
if (inc.next()) {
return inc.getDisplayValue(‘caller_id’);
}
return ”;
},
// Function 2: Get Caller Location
getCallerLocation: function(incSysId) {
var inc = new GlideRecord(‘incident’);
inc.addQuery(‘sys_id’, incSysId);
inc.query();
if (inc.next()) {
var caller = new GlideRecord(‘sys_user’);
caller.addQuery(‘sys_id’, inc.getValue(‘caller_id’));
caller.query();
if (caller.next()) {
return caller.getDisplayValue(‘location’);
}
}
return ”;
},
// Function 3: Get Priority of Incident
getPriority: function(incSysId) {
var inc = new GlideRecord(‘incident’);
inc.addQuery(‘sys_id’, incSysId);
inc.query();
if (inc.next()) {
return inc.getDisplayValue(‘priority’);
}
return ”;
},
//Function 4: Get the state of the Incident
getState: function(incSysId) {
var inc = new GlideRecord(‘incident’);
inc.addQuery(‘sys_id’, incSysId);
inc.query();
if (inc.next()) {
return inc.getDisplayValue(‘state’);
}
return ”;
},
//Function 5: Get Caller’s Phone number
getPhoneNumber: function(incSysId) {
var inc = new GlideRecord(‘incident’);
inc.addQuery(‘sys_id’, incSysId);
inc.query();
if (inc.next()) {
var caller = new GlideRecord(‘sys_user’);
caller.addQuery(‘sys_id’, inc.getValue(‘caller_id’));
caller.query();
if (caller.next()) {
return caller.getDisplayValue(‘mobile_phone’);
}
}
return ”;
},
type: ‘QAIncidetnUtil ‘
};
Test Script Include in Background Script
var util = new QAIncidetnUtil();
var incSysId = ‘e14d3c9e53326290c07456a0a0490edb’;
gs.info(“Caller: ” + util.getCaller(incSysId));
gs.info(“Caller Location: ” + util.getCallerLocation(incSysId));
gs.info(“Priority: ” + util.getPriority(incSysId));
gs.info(“State: ” + util.getState(incSysId));
gs.info(“Phone Number: ” + util.getPhoneNumber(incSysId));
Output

Prepared by: Qazi Zaid Anwar