Getting double comments when we use before update BR

subbarayudu
Tera Contributor

I have a choice  field called HITRUST , written a BR  when its changes to any value i need to populate  previous valued i the automated comments in that same table.

But here I am facing a challenge when i use before update  BR with out currnnt.update() getting two automated comments(duplicate).

i use after update  BR with  currnnt.update() getting only one  automated comments.

Any suggestions pls, to get only one automated comments.

 

subbarayudu_0-1723053265562.png

Thanks in advance

 

 

9 REPLIES 9

Satishkumar B
Giga Sage
Giga Sage

@subbarayudu To avoid duplicate automated comments, use an After Update Business Rule. This approach ensures comments are added after the record is updated, preventing interference with the current update process. Avoid recursive updates by directly appending the comment to `current.u_automated_comments` instead of using `current.update()`, which could trigger the rule again.

refer below code:

 

(function executeRule(current, previous /*null when async*/) {
var comment = "";
var datestmp = new GlideDateTime();

if (previous.u_hitrust_type != current.u_hitrust_type) {
if (previous.u_hitrust_type == "") {
comment = datestmp + ' The prior HITRUST type was None';
} else {
comment = datestmp + ' The prior HITRUST type was ' + previous.u_hitrust_type;
}
// Append comment to the existing value
current.u_automated_comments += (current.u_automated_comments ? '\n' : '') + comment;
}
})(current, previous);

 

———————————————-
Please consider marking my reply as Helpful👍 and/or Accept Solution, if applicable. Thanks!

@Satishkumar B  for after update BR I have used your code and tested still getting the duplicate comments.

subbarayudu_0-1723110050035.pngsubbarayudu_1-1723110093523.png

Could you pls suggest me the another to avoid duplicate comments

 

@subbarayudu Can you show me your condition for execution of this script. 

@subbarayudu I checked in the pdi it is giving me single comment

SatishkumarB_0-1723223014557.png