Suzanne Smith
ServiceNow Employee
ServiceNow Employee

"You have to learn the rules of the game. And then you have to play better than anyone else."

-Albert Einstein

 

One of our favorite rules of the game in ServiceNow is business rules. A business rule is JavaScript that runs when a table is queried or when a record is inserted, displayed, updated, or deleted. Questions about business rules appear regularly here in the community, but lately we have had a number of questions specifically about using conditions with business rules.

 

Remember that a condition on a business rule tells the business rule when it should execute. The condition is evaluated first and the JavaScript only runs if the condition is true. Why is this good? Because it can improve performance and if you have a lot of business rules or business rules that run frequently, it can make a real difference.

 

Here's an example. In the business rule below, the if statement current.rating.changes() determines if the rest of the script runs and calculates a new average rating for a knowledge base article. The system loads and evaluates the business rule after every insert or update.

 

business_rule_conditions1.png


Alternatively, take the if statement out of the script and place it in the Condition field. Now, the condition is checked first and the script only runs if the condition is true. So, in this case, the script calculates the new average rating for the article only after a new rating is added to a knowledge base article.

 

business_rule_conditions2.png


Here are some additional tips and tricks when working with business rule conditions:

 

ServiceNow offers more information about business rules in the product documentation:


Business Rules

Scripting in Business Rules

Debugging Business Rules - ServiceNow Wiki

4 Comments