Business Rule triggered two times, updating the work twice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2023 11:05 PM
(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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2023 11:26 PM
On which table this business rule is getting executed? and Is it an onbefore/onafter Business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2023 11:46 PM
It is getting triggered on sc_req_item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2023 11:48 PM
It is before update. There's another item in the same request, so the trigger condition is Item is that another Item and State is closed complete

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 12:28 AM
try below script:
(function executeRule(current, previous /*null when async*/ ) {
var comment = new GlideRecord('sc_req_item');
comment.addEncodedQuery('request=' + current.request + '^cat_item=7d3212551b68a1d0923e6311f54bcbda');
comment.addEncodedQuery("sys_id!=" + current.sys_id);
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);
Thank you,
Ali