Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

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);

 

2 REPLIES 2

Ankur Bawiskar
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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

 

The business requirement is to have comments added from a REQ to the RITM form in Service Operations.

 

I have managed to do this but I am getting duplicate comments when I submit a comment. (See screenshot 'Add comment test 2' appears twice)

 

I would like to know if there is a way to remove the top comment through the script or configuration.

 

Thank you