Potential Recursive Business Rules - current.update()

Impact area

Performance

Performance
Severity

High

Affected element

Business rules

Rule ID

 SN-0005-EXTENDED

Impact

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. 


Remediation

When a recursive Business Rule is detected, ServiceNow stops it and logs the error in the system log. However, this behaviour may cause system performance issues and is never necessary. You can avoid recursive calls by adding current.setWorkflow(false) before current.update()

Code examples

Compliant


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

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

})(current,previous);


Non-compliant


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

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

})(current,previous);


Time to fix

40 min





Last modified on Sep 5, 2023