Business Rule triggered two times, updating the work twice

Saurav Bhardwa2
Tera Contributor

(function executeRule(current, previous /*null when async*/ ) {

var comment = new GlideRecord('sc_req_item');
comment.addEncodedQuery('request=' + current.request + '^cat_item=7d3212551b68a1d0923e6311f54bcbda');
comment.query();
if (comment.next()) {

comment.work_notes = current.number + ' has been marked as Closed Complete';
comment.update();
gs.info('doctorDoom ' + current.number + ' has been marked as Closed Complete');
}

})(current, previous);

This is the code I am using, but it is updating the work notes twice in the RITM table. May I know why this is happening, is this something I need to change in my code? I have checked logs as well it is populating the notes twice

7 REPLIES 7

HI Ahmmed,
Thank you for your response but it's still updating the work notes twice

 

Ashir Waheed
Kilo Sage
Kilo Sage

Hi @Saurav Bhardwa2 

 

Just remove the Comment.update(); statement from the script. Since BR is running before update. Update is running two times. One as you update and second in the script.

 

Regards,

Ashir Waheed

Thanks for your response, if I tried removing comment.update, now it is not updating the notes at all