no current update() in Business Rule .. BUT it does not update ...?!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 03:13 PM
Hi,
just wondering ... I have a business rule (after) that should clear a value on the current table ... and as the log shows before and after the current.fiedname ... it works, just the changes are not saved ... . For my understanding a current.update() after changing the current.fieldname would be logical ... NO!?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 03:39 PM
Hi Vem
In theory is correct, but according to the best practice..(Business Rules Best Practices - ServiceNow Wiki )
before | Use to update information on the current object. For example, a business rule containing current.state=3; would set the State field on the current record to the state with a Value of 3. |
after | Use to update information on related objects that need to be displayed immediately, such as GlideRecord queries. |
4 Prevent Recursive Business Rules
Avoid using current.update() in a business rule script. The update() method triggers business rules to run on the same table for insert and update operations, leading to a business rule calling itself over and over. Changes made in before business rules are automatically saved when all before business rules are complete, and after business rules are best used for updating related, not current, objects. When a recursive business rule is detected, the system stops it and logs the error in the system log. However, current.update() causes system performance issues and is never necessary.
Maybe your BR is seen as recursive and for this reason it is stopped by the system.
I would suggest to have a look to the log.
I hope this help
Cheers
R0b0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 03:47 PM
I have no idea how to check if BR is seen as "recursive" .. log doesn't tell me that.
I changed to before .. and same same ... not cleared

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 07:58 AM
Found an other way to do it ... anyhow thank you all!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 03:43 PM
Im wondering, why clear a value right after you saved it? Perhaps there is a better way to solve the requirement you have that leaves you to try this solution.
Never use current.update in a Business Rule
//Göran