Can we use update function multiple time in BR ?

shaik_irfan
Tera Guru

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

}


}

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Shaik,



As a best practice use BEFORE business rule to update the current objects and create an AFTER business rule to update the record in another table.



P.S: Don't use current.update() when before business rule is created.


The above code i written on after BR, my concern is just to update the field value on some condition is it required to create an extra BR so thats the reason i just included 1 line code in the existing BR, will that impact in future ???


Hello Shaik,



Go with two business rules to avoid performance issues. Please let me know if you have additional questions.