
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
"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.
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.
Here are some additional tips and tricks when working with business rule conditions:
- Note that if there is no condition for a business rule, then the rule is true by default.
- Community member, Scott Parry had an issue with a business rule condition not firing correctly and Justin Drysdale and AKT_SN offered suggestions. Scott tweaked the script and added a new business rule to obtain the necessary results.
- In the ServiceNow product documentation, the Business Rules Best Practices page offers lots of good advice about business rules, including using conditions.
- In another community post, Sue Frost had a interesting situation with business rules, a record producer, and a wizard. Brad Tilton from Cloud Sherpas provided some helpful advice.
- Felipe Bueno Barbosa had issues with a long condition on a business rule. Geoff Cox and Ashish B were there with answers.
ServiceNow offers more information about business rules in the product documentation:
- 14,153 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.