best practice for updating same record in after business rule

MaharshiC
Tera Contributor

Hi,

 

I want to update the same record in my table after it is inserted . So what is the best practice for updating same record in after insert business rule as current.update() might show recursive call in the health scan reports and without that it is not updating the record like it does for before insert br.

 

Regards,

Maharshi

1 ACCEPTED SOLUTION

Anand Kumar P
Giga Patron
Giga Patron

Hi @MaharshiC ,

 

In the rare case in which a current.update() cannot be avoided and must be used as no other method can be found to accomplish the update as needed, in order to prevent the recursion that can cause the performance issues, the current.update() should be used in conjunction with the setWorkflow(false) function.  As an example, the following code snippet shows a very basic update to a record and use of the setWorkflow() function:

current.status = 1;
current.setWorkflow(false);
current.update();
current.setWorkflow(true);

Refer below ServiceNow kb article 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0715782

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

 

View solution in original post

5 REPLIES 5

Anand Kumar P
Giga Patron
Giga Patron

Hi @MaharshiC ,

 

In the rare case in which a current.update() cannot be avoided and must be used as no other method can be found to accomplish the update as needed, in order to prevent the recursion that can cause the performance issues, the current.update() should be used in conjunction with the setWorkflow(false) function.  As an example, the following code snippet shows a very basic update to a record and use of the setWorkflow() function:

current.status = 1;
current.setWorkflow(false);
current.update();
current.setWorkflow(true);

Refer below ServiceNow kb article 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0715782

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand