Remove duplicate Additional comments appearing in REQ activities field form in SOW

jlance74
Tera Contributor

Is there is a way to remove duplicate additional comments appearing in REQ activities field in SOW?

 

I created a business rule that successfully adds the comments to the RITM form but when I add a comment in the REQ activities field, the comments appear twice.

 

jlance74_1-1757651553385.png

How can I remove the top activity comment?

 

Here is a copy of the business rule.

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

    // Query active catalog tasks related to the same request
    var taskGR = new GlideRecord('sc_req_item');
    taskGR.addQuery('request', current.sys_id);
    taskGR.addQuery('active', true);
    taskGR.query();

    // Get latest journal entries from the current record
    var latestComment = current.comments.getJournalEntry(1) || '';
    var currentNumber = current.getValue('number');
    var currentGroup = current.assignment_group.getDisplayValue() || '';

    while (taskGR.next()) {
        var taskUpdated = false;

       // Check if task already has similar comment
        var taskComment = taskGR.comments.getJournalEntry(1) || '';
        if (latestComment && taskComment.indexOf(latestComment) < 0) {
            taskGR.comments = latestComment; //currentNumber + " - assigned to " + currentGroup + "\n\n" + latestComment;
            taskUpdated = true;
        }

        // Only update if something actually changed
        if (taskUpdated) {
            taskGR.update();
        }
    }

})(current, previous);

 

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@jlance74 

what's your business requirement?

seems it's going in loop

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader