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. We use business rules to achieve tasks such as create events for email notifications and script actions.
We have 4 type of business rule but in this article we will only focus on before business rule.
-
- Before business rule
- After business rule
- Async business rule
- Display business rule
Lets begin to understand After Business Rule In ServiceNow
What is After Business Rule?
After a record is saved to the database. Business Rules executes after form submission and after the record update in the database. This rule is basically used to update information on related objects that need to be displayed immediately, such as GlideRecord queries.

It is clear from the above given image how exactly this rule work in our system. When user click save or update the record. Record gets save into database or table. After Business Rule Script Will get Executed.
Example of after business rule:
Let’s say you have passed the Before BR rule and posted your comment successfully. Now someone like your comment or mark it as help we can have an After BR set up to accomplish this.
To have a better understanding of this concept let’s have a look at below mentioned scenarios.
Scenario 1 – We need to close the task if the respective RITM moves to Closed incomplete.
We will start by creating a new After BR filling all the required fields.

Here is the script to achieve the above-mentioned scenario.

(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item", current.request_item);
gr.addEncodedQuery("stateIN9,-5,1,2,4,7");
gr.query();
if (gr.next()) {} else {
var gr1 = new GlideRecord("sc_req_item");
//gs.log('this is causing issue line 10');
gr1.get(current.request_item);
gr1.state = "10";
//gs.log('this is causing issue line 13');
//gr1.assigned_to = current.assigned_to;
gr1.update();
}
})(current, previous);
Scenario 2 - When Problem is created related Incident state should change to “On hold” and on-hold reason “Awaiting Caller”.
We need to start by selecting table as problem and apply after business rule with action as insert and update.

Here is the script to achieve the above-mentioned scenario

(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('incident');
gr.addQuery('problem_id', current.sys_id);
gr.query();
while (gr.next()) {
gr.state = '3';
gr.hold_reason = '1';
gr.update();
}
})(current, previous);
Scenario 3 – We need to update the assignment group for Request with assignment group of respective catalog task.
We will start by simply writing a After BR.

Here is the script to achieve the above-mentioned scenario

(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('sc_task');
gr.addQuery('number', current.number);
gr.query();
if (gr.next()) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', gr.request_item);
ritm.query();
if (ritm.next()) {
ritm.assignment_group = gr.assignment_group;
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', ritm.request);
req.query();
if (req.next()) {
req.assignment_group = gr.assignment_group;
req.update()
}
}
}
FAQ








