This is another very common advice about ServiceNow server side scripting. Don't write "current.update()" in business rules or workflows. Calling "update()" method in turn causes the same business rules to run, resulting in multiple recursive calls that never end.
Although ServiceNow detects such recursive calls when they happen and stops the execution (logging an error in the logs), it could result in performance degradation. So, ideally you shouldn't write "update()" in your business rule or the workflow.
Before business rules run before data is inserted/updated in the database, so simply doing the changes in the "current" object would mean those changes would be carried to the database. So, in most of the cases, converting the after business rules to before business rules would suffice. Similarly, any script written in the workflows results in the updates in the underlying records, so there is no explicit need to write "current.update()" in the workflow either.
If you must update the current record though, best way would be to use it alongside "setWorkflow(false)" method so no further business rules (workflow engine as well) run. This should be a very rare scenario and care must be taken to use order of the business rule such that it doesn't cause issues with any other important business rule that needs to run.
Comments
Post a Comment