
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 08:10 AM
I created an After BR to calculate the calendar_duration on the rm_story table. I need to calculate the diff between the opened_at and closed_at fields, so I set it to run After Active changesTo False. Works great, but it shows up in the activity log once, with a second set of activity showing and a duplicate entry in the Audit History list.
I tried it as a Before BR, but it didn't work because the closed_at isn't populated yet.
Any suggestions would be helpful. Thanks in advance!
Mickey Cegon
Farm Bureau Financial Services, Inc.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 08:19 AM
If you run this as an AFTER BR, it is going to trigger all the BRs again with the current.update().
If closed_at is not populated like you say, try doing a current.setWorkflow(false) right before and give your BR a very high order (10,000) so it runs last to avoid stopping other BRs that might run after it.
Reference:
Business Rules - ServiceNow Wiki
Business Rules Best Practices - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 08:19 AM
If you run this as an AFTER BR, it is going to trigger all the BRs again with the current.update().
If closed_at is not populated like you say, try doing a current.setWorkflow(false) right before and give your BR a very high order (10,000) so it runs last to avoid stopping other BRs that might run after it.
Reference:
Business Rules - ServiceNow Wiki
Business Rules Best Practices - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 08:56 AM
Thanks for the quick response, Chuck. I took a look at the order of all the BR running, and it ends up that the Set Closure Fields BR was set to an order of 10,000. So, I changed my BR to a Before, changed the Order to 20,000, and removed the current.update() from the rule. It now only updates the one time, so I think I've got it fixed. Once I set it to wait until the closure fields were actually set, then the calculation worked.
Mickey Cegon

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 09:08 AM
Ding ding ding! Thanks for the update Mickey. Nobody ever pays attention to the order field until things get weird.
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 08:24 AM
Hi Cegon,
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.
Thanks,
Sagar