Can we use update function multiple time in BR ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 09:26 AM
Hello,
I had a requirmeent where i written a customize code and used multiple updates for differnet tables whichis working fine but just want to know is this is a best practise ?
function ba_renderTaskApprovalsMoot() {
current.approval = 'cancelled';
current.update(); // this is to update my current table
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id);
var qc = gr.addQuery('state', 'requested');
qc.addOrCondition('state', 'not requested');
qc.addOrCondition('state', 'approved');
gr.query();
while (gr.next()) {
gr.state = 'cancelled';
gr.update(); // this is to update my approval table
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 09:35 AM
Best practice is that when updating the current record, you should do it in a BEFORE business rule when possible, that way you don't need to use the current.update() statement.
When updating another table, you should use an AFTER business rule, to ensure that the update to the primary record is committed before making updates to related records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 05:43 PM
Best practice to update the record
----------------------------------------------
1) In Before business rule, we don't need to update the current record
2) In After business rule, current.update( ) can be used to update the current record as well as other tables also.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 06:06 PM
Hello Shyam,,
To add, option2 if used in special circumstances should have setWorkflow() method to prevent recursion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 06:16 PM
Hello Pradeep,
If it goes in recursion only, then setWorkFlow() is needed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 08:10 PM
Can you please share the use case when to use and when not to and also point to the docs link if any.