You are currently viewing When To Use current.update() in Business Rules?

When To Use current.update() in Business Rules?

Hello ServiceNow Developers,

You must have worked on ServiceNow Business Rules in your development timeline. I have written hundreds of business rules and used current. update() in many of them. However, I mostly used it after the business rule.

Recently, I came across a document on the ServiceNow Knowledge forum and learned that ServiceNow does not recommend it because of a business rule.

The current.update() function should be avoided within any Business Rule.

It is the recommended best practice of Business Rules.

So, I did a little research and combined all the thoughts and observations in this article.

My ServiceNow YouTube Channels

Why avoid current. update() in any business rule?

We should avoid the current.update() function in Business rules. The main reason to avoid the update function in BR is that it can lead to recursive calls to the same business rule. System (SNOW) has internal detectors for this, but to prevent an endless recursive call of BR, which can cause performance issues in this instance,

business-rule-analysis

There is rarely a case when current. Update () should never need to be used in a Business Rule. Let’s discuss each type of business rule one by one.

current. update() in Before Business Rule?

Before BR, current. update is unnecessary, as SNOW saves all values stored in the current object after BR executes.

E.g., current.state = 7 ; current.description=” hello there”;

current. update() in After Business Rule?

In After BR, try to rethink using current. Update () as this can cause Before BR to run again. To avoid this, change your After BR to Before BR so you won’t need to use current. Update.

current. update() in Async Business Rule?

Async BR executes after data is modified in the database, so its solution is similar to After BR.

current. update() in Display Business Rule?

Display BR runs when the record is first displayed on the screen. So, updating a record when it is just accessed is not a good practice. Alternatively, use client scripts in those cases.

When to use current. update()?

In the rare case in which a current update() cannot be avoided, to prevent recursion that can cause performance issues, current. The update should be used in conjunction with setWorkflow(false).

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

This will suppress any business rules from triggering and will also prevent the update from being audited.

So, friends, this is all about the current usage. update(). You can make your changes and try to avoid using the function.

Leave a Reply