Prevent recursive business rules

This article is based on the ServiceNow documentation article. See the original article on the ServiceNow doc site: Prevent Recursive Business Rules

Do not use current.update() in a Business Rule script. The update() method triggers Business Rules to run on the same table for insert and update operations, potentially leading to a Business Rule calling itself over and over. Changes made in before Business Rules are automatically saved when all before Business Rules are complete, and after Business Rules are best used for updating related, not current, objects. When a recursive Business Rule is detected, ServiceNow stops it and logs the error in the system log. However, this behavior may cause system performance issues and is never necessary.

(function executeRule(current, previous /*null when async*/) {

	current.state = 2;
	current.update();  // Do NOT do this in a business rule //

})(current,previous); 

You can prevent recursive Business Rules by using the setWorkflow() method with the false parameter, current.setWorkFlow(false). This will stop Business Rules and other related functions from running on this database access. The combination of the update() and setWorkflow() methods is only recommended in special circumstances where the normal before and after guidelines mentioned above do not meet your requirements.




Last modified on Aug 23, 2023