CADCertified Application Developer

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

WhenRunsTypical use
beforeBefore the record is savedChanging fields on the same record; validating and aborting
afterAfter the record is savedUpdating related records
asyncAfter saving, in the backgroundSlow work such as calling another system
displayBefore the form is shownPutting 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

  • current is the record being saved, and previous holds 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() or gs.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.
Exam tip: which timing?Change the same record: before. Change other records: after. Slow external work: async. Data for the form: display.

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.

script-editor

Step 3 · Check

Exam-style questions

Select an answer and check it. Every answer includes an explanation.