Using current.update() in after business rule

SounakPal
Tera Contributor

In my business rule I have used current.update() and it works as expected but it throws the recursive BR error during the validation check. Tried using setWorkFlow(false) after the update statement but still of no avail. So wanted to know if there's any other subsitution to fix this error.

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @SounakPal,

 

Firstly, as I'm sure you've read and have been directed, avoid using current.update() - It is against best practice for this very reason you're experiencing.

I know SN's docs and Best Practices advise you can prevent recursive Business Rules by using the setWorkflow() method with the false parameter, "current.setWorkFlow(false)" - it also states this should only be used under special circumstances. My recommendation - it should still be avoided.

 

Depending on your logic, can you change the business rule to a 'before' business rule and remove the current.update()?

Please try this.

 

If you share you're code (high level), there may be another solution available (depending on what you're trying to achieve)

But to answer your question directly - do not use current.update() in an after business rule. Change the Business Rule ('BR') to a before 'BR' and remove the current.update() statement.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

https://developer.servicenow.com/dev.do#!/guides/utah/now-platform/tpb-guide/business_rules_technica...

View solution in original post

5 REPLIES 5

Robbie
Kilo Patron
Kilo Patron

Hi @SounakPal,

 

Firstly, as I'm sure you've read and have been directed, avoid using current.update() - It is against best practice for this very reason you're experiencing.

I know SN's docs and Best Practices advise you can prevent recursive Business Rules by using the setWorkflow() method with the false parameter, "current.setWorkFlow(false)" - it also states this should only be used under special circumstances. My recommendation - it should still be avoided.

 

Depending on your logic, can you change the business rule to a 'before' business rule and remove the current.update()?

Please try this.

 

If you share you're code (high level), there may be another solution available (depending on what you're trying to achieve)

But to answer your question directly - do not use current.update() in an after business rule. Change the Business Rule ('BR') to a before 'BR' and remove the current.update() statement.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

https://developer.servicenow.com/dev.do#!/guides/utah/now-platform/tpb-guide/business_rules_technica...

SounakPal
Tera Contributor

Hi Robbie thank you for the recommendation. I'll change the run condition accordingly.

No worries at all @SounakPal. Happy to help.

 

Thanks, Robbie

Anurag Tripathi
Mega Patron
Mega Patron

is there any reason why your BR cant be used before ? and without the current.update?

-Anurag