1) What is a Business Rule?
A Business Rule is a piece of server-side JavaScript that the platform executes automatically based on database operations on a table — insert, update, delete, or query — rather than being triggered by a user clicking a button or a UI action. It’s the primary way to enforce logic, validation, and automation “behind the scenes.”
2) Why do we use Business Rules?
• Enforce data integrity — validate or default field values before they’re saved
• Automate processes — auto-assign records, send notifications, update related records
• Centralize logic — server-side rules apply no matter how the data was changed (form, import, API, workflow), unlike client scripts which only fire from the UI
• Reduce manual work — replace repetitive manual steps with automatic actions
3) Where is it used?
• Table-level: attached to a specific table (e.g., Incident, Change Request, or a custom table)
• Runs on the server, so it applies uniformly across the UI, REST/SOAP API calls, imports, workflows, and scheduled jobs
• Common in ITSM, CRM, HR Service Delivery, and any custom application built on the platform
4)How does it work?
1. You define a table and a condition (when the rule should fire, e.g., “priority changes to 1 – Critical”)
2. You choose when it runs (before, after, async, display — see below)
3. You write a script (using the current object representing the record) that performs the logic
4. The platform’s engine evaluates the condition on every relevant database operation and executes the script if it matches
5. Types of Business Rules (by “When”) Type When it Runs Typical Use Case
| Type | When it Runs | Typical Use Case |
| Before | Before the record is saved to the database | Validate/modify field values, set defaults, prevent invalid saves (can abort the action) |
| After | After the record is saved | Update related records, trigger notifications, since the record already has its final saved state (e.g., generated sys_id, number) |
| Async | After the transaction completes, in a scheduled background job | Long-running or non-time-critical tasks (e.g., sending emails, heavy calculations) so the user isn’t stuck waiting |
| Display | Before the form is rendered to the user (runs on server but sends data to client) | Pass server-side data to the client script/form (e.g., populate a variable used by a client script) without needing a full round trip |
| Query | When a query is run against the table (before results return) | Add additional filtering logic, like row-level security, to every query on that table |
When to use each:
• Before → when you need to stop or alter the save itself (validation, defaulting values)
Scenario: A Critical (P1) incident must not be saved without an Assignment group.
Configuration: Table: Incident | When: before | Insert: checked | Update: checked | Condition: Priority is 1 – Critical

(function executeRule(current, previous) {
if (current.assignment_group.nil()) {
gs.addErrorMessage(‘Assignment group is mandatory for P1 incidents.’);
current.setAbortAction(true);
}
})(current, previous);

Result: Saving a P1 incident with an empty Assignment group is blocked and the error message appears.

• After → when you need the record’s final state to act on it or touch other records
Scenario: When a parent incident is Resolved, resolve its active child incidents too.
Configuration: Table: Incident | When: after | Update: checked | Condition: State changes to Resolved

(function executeRule(current, previous) {
var child = new GlideRecord(‘incident’);
child.addQuery(‘parent_incident’, current.sys_id);
child.addActiveQuery();
child.query();
while (child.next()) {
child.state = 6;
child.close_code = current.close_code;
child.close_notes = ‘Resolved along with parent ‘ + current.number;
child.update();
}
})(current, previous);

• Async → when the action is not urgent and shouldn’t block the user’s save/submit
Scenario: When a P1 incident is created, queue an event that sends an email notification without making the user wait.
Configuration: Table: Incident | When: async | Insert: checked | Condition: Priority is 1 – Critical

(function executeRule(current, previous) {
gs.eventQueue(‘incident.critical.created’, current,
current.caller_id, current.assignment_group);
})(current, previous);

• Display → when the client-side needs data that’s expensive or insecure to fetch via client script (like a GlideRecord lookup)
Scenario: When an incident form opens, show a warning if the caller already has many open incidents.
Configuration: Table: Incident | When: display

javascript
(function executeRule(current, previous) {
var ga = new GlideAggregate(‘incident’);
ga.addQuery(‘caller_id’, current.caller_id);
ga.addActiveQuery();
ga.addAggregate(‘COUNT’);
ga.query();
g_scratchpad.openIncidents = ga.next() ? parseInt(ga.getAggregate(‘COUNT’), 10) : 0;
})(current, previous);

