Announcing the Global SNUG Board of Directors. Learn more here

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Before and After Business Rules

Not applicable

Wanted to take a moment to discuss the different between before and after business rule.

When a record is updated in since of Service-now, operations occur in this sequence:

Before business rules run -> Actual database write occurs -> after business rules run

To give a concrete example, if you press "update" while looking at an incident:

1) All "before update" incident business rules run
2) SNC actually posts your update into the database
3) All "after update" incident business rules run

What this means to you as a script writer is that you can do different things with before and after rules.

Before Rules:

Since they run before the physical update, any changes you make to the record during the rule are recorded as part of the update. This makes before rules the ideal place to set values as part of the save cascade. On the other hand, at the time the before rule is running, the current set of changes hasn't yet written through to the database, and may not be, e.g. the update could be cancelled because of missing mandatory fields, other business rules, etc.

After Rules:

Since they run after the physical update, any changes you make to the record during this rule will not be reflected in the database. This means this is a bad place to set values. On the other hand, at the time this rule runs, your database update has written through, so this is the right place to do things like throw custom events.

Summary:


[*]Use before rules to set values
[*]Use after rules to react to inserts/updates/deletes
3 REPLIES 3

wbmore
Kilo Expert

Thanks for the explanation Pat. I have a much better idea of what these should be used for now.


This is also useful information from the wiki.

The order of execution is as follows:


[*] "before" business rules with order less than 1000
[*] engines (assignment rules, escalations)
[*] "before" business rules with order greater than 1000
[*] database operation (insert, update)
[*] "after" business rules with order less than 1000
[*] engines (approval rules)
[*] "after" business rules with order greater than 1000


adminaa
Kilo Contributor

Thanks , this is useful.