Facing Issue in copying Comments from parent to child and child to parent

i_sachin_
Tera Contributor
Hi Servicenow community, I'm actually facing a problem in copying comments  from incident to work order and from work order to work order task, then copying work order task to work order and incident. The comments added by users in the portal will go from incident to work order to work order task, and the comments added by technicians will go from work order task to work order to incident. However, when I do this, it actually recurses, copying the same comment again. How can I resolve this issue?
 
 
I'm attaching my business rule code here,
 
when to run: after update
filter condition: comments changes
 
Business rule for Incident to work order:
 
(function executeRule(current, previous /*null when async*/ ) {
 
    // Add your code here
    var WO = new GlideRecord('wm_order');
    // check for exising record.
    WO.addQuery('parent', current.number);
    WO.query();
    if (WO.next()) {
        var commentstext = current.comments.getJournalEntry(1);
        commentstext = commentstext.replace(/.*\)\s*/, '');
        WO.comments = commentstext;
var WorkOrderID = WO.update();
    }
})(current, previous);
 
when to run: after update
filter condition: comments changes
 
Business rule for Work Order to Work order task:
 
(function executeRule(current, previous /*null when async*/ ) {
 
    // Add your code here
    var WOT = new GlideRecord('wm_task');
    // check for exising record.
    WOT.addQuery('u_parent_wot', current.number);
    WOT.query();
    if (WOT.next()) {
        var commentstext = current.comments.getJournalEntry(1);
        commentstext = commentstext.replace(/.*\)\s*/, '');
        WOT.comments = commentstext;
var WorkOrderID = WOT.update();
    }
})(current, previous);
 
and two more business rules are there, when to run: after update and filter condition: comments changes. These rules handle copying comments added by technicians from work order tasks to work order and then Work order to incident
@Ankur Bawiskar can you help me with this?

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@i_sachin_ 

so basically it's going in loop?

if yes then this link has solution from Sravani

Sync'ing RITM and SCTASK work notes \ additional comments 

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@i_sachin_ 

so basically it's going in loop?

if yes then this link has solution from Sravani

Sync'ing RITM and SCTASK work notes \ additional comments 

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

Thanks @Ankur Bawiskar It's worked perfectly