Business rules and scripting
ServiceNow CSA · Lesson 23 of 24 · 2:45:21
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the ServiceNow Certified System Administrator (CSA) exam. In this lesson: when business rules run, what business rules do without a script, server-side scripting with GlideRecord and script includes, and choosing the right tool. Includes three original practice questions, with Brackenridge Engineering, a fictional engineering firm whose IT team runs its ServiceNow instance, as the example.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Every incident, every channel
Brackenridge wants every incident from its executives flagged as urgent, whether it arrives through a form, an email, or a web service. A client script would only catch the forms. This logic belongs on the server, in a business rule.
When business rules run
A business rule is a server-side script that runs when a record is displayed, inserted, updated, or deleted, or when a table is queried. A before rule runs after the user submits the form, but before the record is saved in the database, and an after rule runs once it is saved. An async rule runs later, through a scheduled job, so the user does not wait, and a display rule runs just after the data is read, before the form appears. Each rule selects its operations, Insert, Update, Delete, or Query, and when several rules apply, they run in order, from the lowest number to the highest. And business rules apply to records however they arrive, through forms, lists, or web services, unlike client scripts.
What business rules do
Business rules can set field values, display messages, update child tasks, or abort the database transaction, so that a record is not saved. Admins can set field values, add messages, and abort a transaction without writing any script. Filter conditions decide when a rule runs, and the Advanced view adds a script, where the current object holds the record being saved. Avoid calling current dot update in a business rule: before rule changes are saved automatically, and after rules are best for updating related records. And for any new process automation, ServiceNow now recommends flows in Workflow Studio, which are easier to extend and upgrade than business rules.
Server-side scripting
Server-side scripts run on the server, in business rules, script includes, scheduled jobs, and other server features, and they are written in JavaScript. They use server-side Glide APIs, like GlideRecord, to query and change records in the database. Script includes store reusable server code, a function or a class, under System Definition, then Script Includes, and they load only when called. That is why ServiceNow prefers script includes over global business rules, which load on every page. And a client callable script include can be called from client scripts, behind an access control, while Scripts Background lets admins run any script on the server, so use it with great care.
Choosing the right tool
On the form, start with UI policies, and use client scripts for logic that conditions cannot express. Remember that client scripts and UI policies improve the user experience, but provide no data security. On the server, data policies enforce mandatory and read-only fields on all data, and access control rules decide who may read or change it. Business rules hold the logic that must run on every save, keep them small, give them conditions, and do not change the base system rules. And to troubleshoot a business rule, use the debug options under System Diagnostics, then Session Debug, and the system log.
Recap
Let's recap. Business rules run on the server, before, after, or asynchronously around a save, on display, or on a query. They apply to records from every channel, and they can set values, show messages, or abort a save without any script. Avoid current dot update, and prefer flows in Workflow Studio for new process automation. Script includes hold reusable server code, and load only when called. And for security, rely on access control rules and data policies, never on client scripts.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
Brackenridge wants the location of each new incident filled in from the caller’s record, as part of the same save, so the incident is never stored without it. Which business rule fits?
- An after insert rule
- A before insert rule
- An async insert rule
- A display rule
Show the answer
A before insert rule
A before rule changes the record before it is saved, and its changes are saved automatically. “An after insert rule” runs only after the record is saved, so it would need a second update. “An async insert rule” runs later, so the incident would be stored without its location at first. And “A display rule” only runs when the form is displayed, not when the record is saved.
Several business rules at Brackenridge need the same date calculation, and the admin wants to write it once. Where should the code live?
- In a script include
- In a global business rule
- In an onLoad client script
- In Scripts - Background
Show the answer
In a script include
A script include stores reusable server code, and loads only when it is called. “In a global business rule” would load on every page, which is why script includes are preferred. “In an onLoad client script” runs in the browser, so business rules cannot call it. And “In Scripts - Background” runs a script once, and keeps nothing for other scripts to reuse.
To keep agents from reading a salary field, a Brackenridge admin plans a client script that hides it on the form. What is wrong with this plan?
- Nothing, hiding the field protects it
- It should be an onSubmit client script
- It should be a UI policy instead
- Client scripts give no data security
Show the answer
Client scripts give no data security
Client scripts provide no data security, so the salary needs a read access control rule. “Nothing, hiding the field protects it” is wrong, since hiding a field on a form does not protect the data. “It should be an onSubmit client script” would only run when the form is submitted, and still protect nothing. And “It should be a UI policy instead” also works on the form only, so the data would stay readable elsewhere.