no current update() in Business Rule .. BUT it does not update ...?!

Zod
Giga Guru

Hi,

just wondering ... I have a business rule (after) that should clear a value on the current table ... and as the log shows before and after the current.fiedname ... it works, just the changes are not saved ... . For my understanding a current.update() after changing the current.fieldname would be logical ... NO!?

6 REPLIES 6

Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Vem



In theory is correct, but according to the best practice..(Business Rules Best Practices - ServiceNow Wiki )


beforeUse to update information on the current object. For example, a business rule containing current.state=3; would set the State field on the current record to the state with a Value of 3.
afterUse to update information on related objects that need to be displayed immediately, such as GlideRecord queries.

4 Prevent Recursive Business Rules

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.



Maybe your BR is seen as recursive and for this reason it is stopped by the system.


I would suggest to have a look to the log.



I hope this help


Cheers


R0b0


I have no idea how to check if BR is seen as "recursive" .. log doesn't tell me that.


I changed to before .. and same same ... not cleared


Found an other way to do it ... anyhow thank you all!


Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Im wondering, why clear a value right after you saved it? Perhaps there is a better way to solve the requirement you have that leaves you to try this solution.



Never use current.update in a Business Rule  



//Göran