How do I avoid using current.update() in a business rule script by using setWorkflow() method with the false parameter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2018 12:22 PM
This script was developed to add users to the watchlist for every case if a Watchlist = True check box is active in their user profile. However this business rule is causing some recursive issues. Based on the feedback from SN I need to stop using current.update and start using the setWorkflow(false) method. Can someone help me modify the code below appropriately.
This is the feedback from ServiceNow
First and foremost, Its not recommended to use current.update() in "After" Business rule.
Because it will lead to recursive call. It is documented here :
-https://docs.servicenow.com/bundle/kingston-application-development/page/script/business-rules/reference/r_HowBusinessRulesWork.html#d746702e265
"Avoid using current.update() in a business rule script. The update() method triggers business rules to run on the same table for insert and update operations, 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, the system stops it and logs the error in the system log. However, current.update() causes system performance issues and is never necessary.
You can prevent recursive business rules by using the setWorkflow() method with the false parameter. 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."
In this business rule "Set watch_list acc to addtocasewatchlist" I see you are doing current.update() as many times as that of people in the watchlist.
This is causing the case record to get updated as many times at the same time frame.
When to Run: When = After , and Insert = True
Advanced
(function executeRule(current, previous /*null when async*/) {
// Add your code here
// var watchlist = [];
// watchlist = current.watch_list.split(',');
var str1 = current.watch_list;
var gr = new GlideRecord("sys_user");
gr.addQuery("company",current.account);
gr.addQuery("u_add_to_case_watchlist",true);
gr.query();
while (gr.next()) {
var str2 = gr.sys_id;
if(!current.watch_list)
{
current.watch_list = gr.sys_id;
}
else if(str1.indexOf(str2) == -1)
{
current.watch_list = current.watch_list +','+ gr.sys_id;
}
current.update();
}
})(current, previous);
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2018 10:12 AM
I need that in after business rule ......

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2018 11:00 AM
This can run as before and accomplish the same task. The 'setWorkflow(false)' will just force this record update to ignore other BR's that run. No matter what, you'll want to remove the 'current.update()' as that's causing the issue.
Why would this need to run as 'After', as opposed to 'Before'?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2019 08:38 AM
How about a business rule that only runs on insert (async) and uses current.update()? This shouldn't invoke recursion as the BR only runs on insert. Can anyone validate this?
Thanks,
Scott

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2019 11:03 AM
yes, it wont. but it cannot used for the above functionality
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2019 08:45 AM
How about we fire off a event and handle it in the event handling code?
SN Community please validate.
Vinod Kumar Kachineni
Community Rising Star 2022