- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 02:41 PM
Hey everyone,
I know that current.update() is not a best practice when working with business rules, but is it appropriate to use gr.update() in a business rule to update a record on another table?
In my example, I have an 'after' business rule that runs on sc_request but updates the RITMS that are created with that request.
var relatedItemsInfo = [];
var item = new GlideRecord('sc_req_item');
item.addQuery('request',current.sys_id);
item.query();
while (item.next()) {
relatedItemsInfo.push(item.number + ': ' + item.short_description);
}
var updateItem = new GlideRecord('sc_req_item');
updateItem.addQuery('request', current.sys_id);
updateItem.query();
while (updateItem.next()) {
var relatedNote = 'Note to include.' + '\n' + relatedItemsInfo.join('\n');
updateItem.comments = relatedNote;
updateItem.update();
}
Is my use of updateItem.update() the best way to do this or should I be updating that record in a different way?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 02:50 PM
Hi,
What you have is fine. Your observation on the use of 'current.update()' is correct, but doesn't apply here since the record is on another table. One consideration is do you want business rules on sc_req_item table to run when you update a record there? If not add 'updateItem.setWorkflow(false);' before the update(). Others here may post their thoughts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 02:50 PM
Hi,
What you have is fine. Your observation on the use of 'current.update()' is correct, but doesn't apply here since the record is on another table. One consideration is do you want business rules on sc_req_item table to run when you update a record there? If not add 'updateItem.setWorkflow(false);' before the update(). Others here may post their thoughts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 09:13 AM
Thanks very much, Bert!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2024 08:25 AM