Lessons › Domain 2: Application User Interface (20%) › Lesson 7
Server-side Scripting
About 16 minutes · Last checked against the CAD blueprint (January 2026): 4 December 2026
Step 1 · Learn
Scripts that run on the instance
Server-side scripts run on the instance, no matter how a record was changed: through a form, a list, an import or a web service. Business rules are the most common.
Business rule timing
| When | Runs | Typical use |
|---|---|---|
| before | Before the record is saved | Changing fields on the same record; validating and aborting |
| after | After the record is saved | Updating related records |
| async | After saving, in the background | Slow work such as calling another system |
| display | Before the form is shown | Putting server data into g_scratchpad for client scripts |
A business rule runs on insert, update, delete or query, filtered by conditions. Use conditions instead of if statements in the script where you can.
Objects in a business rule
currentis the record being saved, andpreviousholds its values before the change.current.setAbortAction(true)stops the save in a before rule.- Do not call
current.update()in a before or after rule on the same record; it causes extra saves and can loop.
GlideRecord
GlideRecord reads and writes records from a script: addQuery() adds a condition, query() runs it, next() moves through results, and insert(), update() and deleteRecord() change data. GlideAggregate counts or sums without loading every record.
Debugging
- Log with
gs.info(),gs.warn(),gs.error()orgs.debug()and read the system log. - Use the Script Debugger to set breakpoints and step through server-side scripts.
- Turn on session debugging, such as Debug Business Rule, to see which rules run.
- Use Scripts - Background to test a snippet on a non-production instance.
Step 2 · Do
Write the loan business rules
Automate the loan request table on the server with the right business rule timing. This is a practice environment of our own design, not the ServiceNow product. Complete the tasks in the task list.
Step 3 · Check
Exam-style questions
Select an answer and check it. Every answer includes an explanation.