- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 12:26 AM
We have 4 types of BR's
1. Before
2. After
3. Asynch
4. Display BR
Could someone please explain in which types of Business Rules (BRs) we use the current.update() method?
@Ankur Bawiskar need your clear explanation on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 12:41 AM
In ServiceNow, the `current.update()` method is used to explicitly save changes to a record. This method is particularly relevant in certain types of Business Rules (BRs) where updating the record is necessary or appropriate.
1. Before Business Rules:
- Usage of `current.update()`: Not recommended.
- Reason: Before Business Rules run before the database operation (insert, update, delete) occurs. Using `current.update()` here can cause recursion issues because the rule itself is triggered by a record operation. Since Before Business Rules are designed to modify the record before it's written to the database, the platform will save changes to the record automatically after the Before Business Rule completes. Using `current.update()` here can lead to infinite loops or unexpected behavior.
2. After Business Rules:
- Usage of `current.update()`: Can be used.
- Reason: After Business Rules execute after the database operation has completed. These rules are ideal for situations where you need to perform additional actions based on the changes made to a record, and then save these further modifications. Since the primary operation has already been completed, using `current.update()` here to make further changes won't cause the same recursion problems as in Before Business Rules.
3. Asynchronous Business Rules (Async BRs):
- Usage of `current.update()`: Can be used.
- Reason: Async BRs run in the background after the database operation has completed. They are used for tasks that don't need to be completed immediately and won't hold up the user interaction. `current.update()` is safe to use here to make further updates to the record, as it won’t affect the performance of the user-facing operations.
4. Display Business Rules:
- Usage of `current.update()`: Not applicable.
- Reason: Display Business Rules execute when a form is loaded and are used to manipulate the data before it is presented to the user. These rules are read-only and are intended to prepare data for display purposes. Thus, using `current.update()` within Display BRs is not relevant, as these rules should not modify the record.
I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 12:41 AM
In ServiceNow, the `current.update()` method is used to explicitly save changes to a record. This method is particularly relevant in certain types of Business Rules (BRs) where updating the record is necessary or appropriate.
1. Before Business Rules:
- Usage of `current.update()`: Not recommended.
- Reason: Before Business Rules run before the database operation (insert, update, delete) occurs. Using `current.update()` here can cause recursion issues because the rule itself is triggered by a record operation. Since Before Business Rules are designed to modify the record before it's written to the database, the platform will save changes to the record automatically after the Before Business Rule completes. Using `current.update()` here can lead to infinite loops or unexpected behavior.
2. After Business Rules:
- Usage of `current.update()`: Can be used.
- Reason: After Business Rules execute after the database operation has completed. These rules are ideal for situations where you need to perform additional actions based on the changes made to a record, and then save these further modifications. Since the primary operation has already been completed, using `current.update()` here to make further changes won't cause the same recursion problems as in Before Business Rules.
3. Asynchronous Business Rules (Async BRs):
- Usage of `current.update()`: Can be used.
- Reason: Async BRs run in the background after the database operation has completed. They are used for tasks that don't need to be completed immediately and won't hold up the user interaction. `current.update()` is safe to use here to make further updates to the record, as it won’t affect the performance of the user-facing operations.
4. Display Business Rules:
- Usage of `current.update()`: Not applicable.
- Reason: Display Business Rules execute when a form is loaded and are used to manipulate the data before it is presented to the user. These rules are read-only and are intended to prepare data for display purposes. Thus, using `current.update()` within Display BRs is not relevant, as these rules should not modify the record.
I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 08:49 PM
Excellent explanation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 12:44 AM
You should always be careful about using this, because it can get you in a loop (although a display BR should never update a record). But I won't give away the rest, since it's Ankur you wanted to answer this.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 12:45 AM
Business Rule Type | Description | Usage of current.update() |
Before | Executes before a record is inserted, updated, or deleted in the database. | Not recommended: Triggers recursion by updating the same record. |
After | Executes after a record is inserted, updated, or deleted in the database. | Recommended: Use to update fields after the initial operation. |
Asynchronous | Runs after a record is saved, allowing other operations to proceed while the rule executes. | Recommended: Use for non-blocking updates post-record operations. |
Display | Executes when a record is retrieved from the database for display. | Not applicable: Updating the current record in a display BR is not useful as it doesn't save changes back to the database. |
……………………………………………………………………………………………………
Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand.