Alternatives to current.update() in Business Rules: Impact and Best Practices?

Astik Thombare
Tera Sage

Hi Community ,

 

I understand that using current.update() in a Business Rule is generally not considered a good practice. However, I have a requirement where it seems necessary to use current.update(). While I know we can use setWorkflow(false) to mitigate some issues, it has a significant impact on various components such as:

  • Audit records
  • Journal fields
  • Workflow engine
  • Notification engine

Given this, I have two specific questions:

  1. If I glide the same record in an after Business Rule (using a GlideRecord query) and then update it, will it have the same impact as using current.update()?

  2. If I call a Script Include from the Business Rule, pass the current object to it, and then glide the same record in the Script Include to update it, will that also have the same impact?

Finally, if both options have the same impact, is there any alternative method to update the current record without using setWorkflow(false) and avoiding these side effects?

 

Thanks in advance !

4 REPLIES 4

Juhi Poddar
Kilo Patron

Hello @Astik Thombare 

For both cases, the impact will be the same as using current.update() unless you explicitly manage workflows, audits, and notifications.

The best approach in such scenarios is to use setWorkflow(false) to mitigate unwanted side effects.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

 

HIROSHI SATOH
Mega Sage
  1. Using gr.update() on the same record in an after Business Rule will have a similar impact to using current.update(). It will trigger the same Business Rules and other automations, potentially causing recursive loops or unexpected behavior.

  2. Calling a Script Include and updating the record there will also have the same effect. The location of the update doesn't change its impact on the system.

  3. Alternatives to avoid side effects: If you want to update the record without side effects, consider the following alternatives:

I don't recommend it though...

Flag to prevent recursion: Add a flag to the record to indicate that the Business Rule should not trigger again for this update. Example:

if (!current.skip_update) {
    current.skip_update = true;
    current.update();
}

 

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @Astik Thombare - It might be helpful to share your requirement so the community can suggest potential solutions. For example, one option is to use GlideAuditor to manually create audit records when setWorkflow(false) is used.

Bert_c1
Kilo Patron

There is the 'disableAutoSysFields API that prevents update to any 'sys' fields.

 

disableAutoSysFields

 

I have some scripts from the past where I used 'autoSysFields(false)' on a GlideRecord Object. Can't seem to find it documented any where at the moment.

 

However the OOB script include 'NumberManager' for one uses 'autoSysFields(false)' at line 98. And 'AssessmentUtils at line 253.