Getting double comments when we use before update BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 10:55 AM
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.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 11:07 AM
@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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 02:42 AM
@Satishkumar B for after update BR I have used your code and tested still getting the duplicate comments.
Could you pls suggest me the another to avoid duplicate comments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 07:41 AM
@subbarayudu Can you show me your condition for execution of this script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 09:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 10:04 AM