How is JavaScript linked with ServiceNow?
- ServiceNow is built on JavaScript.
- Almost all the backend scripts (like Business Rules, Script Includes, Scheduled Jobs) are written using Server-side JavaScript.
- Client-side scripts (like Client Scripts, UI Policies, Catalog Client Scripts) also use JavaScript to control what happens on the user’s browser.
- Glide API is ServiceNow’s built-in library written in JavaScript — it helps you easily interact with the ServiceNow database.
➔ In short: ServiceNow = JavaScript + ServiceNow's Glide API.
JavaScript Interview Questions (ServiceNow Focused)
1. How is JavaScript used in ServiceNow?
Answer:
JavaScript is used both on the client-side (browser) and server-side (server) in ServiceNow.
- Client-side scripting is used for form manipulation, field validation, and UI actions (example: Client Script, Catalog Client Script).
- Server-side scripting is used for database operations, automation, and backend processing (example: Business Rules, Script Includes).
2. What is a Client Script in ServiceNow?
Answer:
A Client Script is a piece of JavaScript that runs on the client’s browser when forms are loaded, changed, or submitted.
It is used to:
- Auto-populate fields
- Validate input before saving
- Display alerts or messages
Example:
function onLoad() {
alert('Welcome to the form!');
}
3. What is a Business Rule in ServiceNow?
Answer:
A Business Rule is a server-side script that runs when records are inserted, updated, deleted, or queried.
It is used to:
- Automate tasks
- Enforce business logic
- Interact with the database
Example:
(function executeRule(current, gsn, gs) {
current.short_description = 'Updated by Business Rule';
})(current, gsn, gs);
4. What is GlideRecord in ServiceNow?
Answer:
GlideRecord
is a JavaScript class used to query, read, update, and delete records in ServiceNow tables (server-side).
Example:
var gr = new GlideRecord('incident');
gr.addQuery('priority', 1);
gr.query();
while (gr.next()) {
gs.info(gr.number);
}
5. Difference between Client-side and Server-side scripting in ServiceNow?
Feature | Client-side | Server-side
Runs where? | User's browser | ServiceNow server
Example | Client Script | Business Rule
Purpose | Form behavior | Database operations
API used | GlideForm (g_form) | GlideRecord (gr), GlideSystem (gs)
6. What is a Script Include in ServiceNow?
Answer:
A Script Include is a reusable server-side JavaScript function or library that you can call from other scripts.
Example:
var HelloWorld = Class.create();
HelloWorld.prototype = {
initialize: function() {},
sayHello: function() {
return "Hello, World!";
},
type: 'HelloWorld'
};
7. How do you call a Script Include from a Client Script?
Answer:
You can use GlideAjax
to call server-side Script Includes from Client Scripts.
Example:
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'sayHello');
ga.getXMLAnswer(function(response){
alert(response);
});
In Short:
Script Type | Place | Language | Example |
---|---|---|---|
Client Script | Browser | JavaScript | g_form.setValue() |
Business Rule | Server | JavaScript | current.update() |
Script Include | Server | JavaScript | Class.create() |