Current.update in Business Rules

Anil74
Tera Guru

Hi All,

I have below questions.

1. What is best practice to use current.update in business rules?

2. where we have to use in before or after BRs and why?

Please explain me.

Thank you.

4 REPLIES 4

scott barnard1
Kilo Sage

Hi Anil



Best practice for current.update is to avoid using it. SN themselves state that it is never necessary, However I've seen it in a lot of places particularly on instances with a long history.



How business rules work



Is a useful link to the docs that is useful for business rules. The old wiki link to BR best practices re-directs here now.



Regards


Aakash Shah4
Tera Guru

Hi Anil,



You can also have a look at this amazing post.


Never use current.update in a Business Rule


ytrottier
Tera Contributor

See KB0715782 for a good detailed explanation.

AbdulAzeez
Mega Guru

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.

 

Do not use current.update() in a before Business Rule.

 

 

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.