ServiceNow Interview Questions: 15 Scripting Questions You Must Know

Scripting questions come up in virtually every ServiceNow technical interview above junior level. Here are the 15 questions that appear most frequently — with the answers framed the way interviewers expect to hear them.

Q1: What is GlideRecord and how do you use it?

GlideRecord is the server-side JavaScript API for interacting with the ServiceNow database. You create an instance for a table, add query conditions, call query(), then iterate results with next(). The key methods are addQuery(), addEncodedQuery(), getValue(), setValue(), insert(), update(), and deleteRecord().

Q2: What is the difference between getValue() and getDisplayValue()?

getValue() returns the raw database value — the sys_id for reference fields, the integer for choice fields. getDisplayValue() returns the human-readable value. Always use getValue() for comparisons in scripts and getDisplayValue() only for output to users.

Q3: What is a Script Include and when would you use one?

A Script Include is a reusable server-side JavaScript library. Use it when the same logic is needed in multiple Business Rules, Scheduled Jobs, or REST endpoints — centralise it in a Script Include so you maintain it in one place.

Q4: What is GlideAjax?

GlideAjax is the mechanism for calling server-side Script Includes from client-side JavaScript. The Script Include must be client callable and extend AbstractAjaxProcessor. The client uses the GlideAjax API to call it asynchronously and receive the response in a callback.

Q5: What is the difference between a Before and After Business Rule?

Before rules run before the record is saved — you can modify the current record's values and they will be included in the save. After rules run after the save — modifications require an explicit current.update() call.

Q6: What is an Async Business Rule and when should you use it?

Async rules run in a separate thread after the record saves. Use them for expensive operations (external API calls, large queries) where the user should not wait for the result.

Q7: What does setWorkflow(false) do?

It prevents Business Rules from firing when you call update() or insert(). Use it in Scheduled Jobs and batch operations to avoid side effects and improve performance.

Q8: How do you prevent a Business Rule from looping?

Looping occurs when a Business Rule calls update() on the same record, triggering itself again. Solutions: check current.operation() and only run on insert or on specific field changes, use setWorkflow(false), or add a custom field as a flag.

Q9: What is GlideAggregate?

GlideAggregate performs aggregate database functions — COUNT, SUM, AVG, MIN, MAX — at the database level without loading records into memory. Use it instead of counting with a GlideRecord loop.

Q10: What is the purpose of g_scratchpad?

g_scratchpad is a data bridge between Display Business Rules (server-side) and Client Scripts. Set values on g_scratchpad in a Display rule, then read them in Client Scripts without needing a GlideAjax call. This avoids the round-trip cost on form load.

Q11: How do you query reference fields in GlideRecord?

Dot-walk through the reference: gr.addQuery('assigned_to.department', 'IT'). For display values: gr.addQuery('assignment_group.nameLIKENetwork'). For the sys_id directly: gr.addQuery('assigned_to', sys_id_value).

Q12: What is the difference between current.update() in a Before vs After rule?

In a Before rule, current.update() triggers an additional database write and can cause a loop — avoid it unless you have a specific reason. In an After rule, current.update() is required to persist any modifications you make to current.

Q13: How do you handle errors in server-side scripts?

Use try/catch blocks and log with gs.error(). Always include meaningful context in error messages: the script name, the record number, and the exception message and stack trace.

Q14: What is an encoded query and how do you use it?

An encoded query is a compact string representation of filter conditions — the same format used in list view URLs. Use addEncodedQuery() to apply it to GlideRecord. Build them using the list view filter UI and copy query.

Q15: What happens to previous in a Business Rule for an Insert operation?

previous is an empty GlideRecord — all fields return empty values. Always check current.operation() before using previous to avoid logic errors on insert.

Want the complete reference?

This article is part of the NowSpectrum knowledge library. Browse all products for cheat sheets, interview prep, and deep-dive reference guides.

Browse All Products →