Copying 'comments' between Request Item and Task but stop replication?

Wesley Breshear
Tera Expert

Hello,

Need help in how address duplication between scripts. Basically what I am trying to do is establish communication between the User entering comments from Service Portal > Request Item page and the Technician working on the request items Task comments.   So when 'additional comments' are added at the Task level they get copied up to the Request Items 'comments' field making the comments available to the User out in the Service Portal.   Then if the user needs to respond back then his/her comments from the Request Item comments field get copied to the Task comments field.   My issue is that my copy rules execute when there is a change to either comments field; task or request item. Hence, then a duplication occurs and the comments get copied back to the same record.   Surprisingly the loop occurs only once where I suppose the logic could create an endless loop of copying comments back and forth. Hope this makes sense?

I am struggling how to establish a condition if the comments come from either copy script not to execute, but obviously execute if comments are added by the user.   Can you assist me with how I can resolve this issue?

BR: Copy Comments to Request Item   [ condition = current.comments.changes() ]

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

var gr = new GlideRecord('sc_req_item');

gr.addQuery('sys_id', current.request_item.sys_id);

gr.query();

while(gr.next()) {

gr.comments = "Comment added from: " + current.number + " | " + current.short_description + "\r\n" + "> " + current.comments;

gr.update();

}

})(current, previous);

BR: Copy Comments to Task(s) [ condition = current.comments.changes() ]

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

var gr = new GlideRecord('sc_task');

gr.addQuery('request_item', current.sys_id);

gr.query();

while(gr.next()) {

gr.comments = "Comment added from: " + current.number + "\r\n" + "> " + current.comments;

gr.update();

}

})(current, previous);

Thank you!

-Wesley

1 ACCEPTED SOLUTION

Michael Fry1
Kilo Patron

While we do push comments from SCTask to RITM (so Requester gets notified), we push Comments from RITM to Worknotes on SCTask but we check if the updater is the same person assigned to the SCtask. If they are, we don't send the comments to SCtask. Here's the script we use to check:




var ritmupdater = gs.getUserID();


     


      var gr = new GlideRecord('sc_task');


      gr.addQuery('request_item',current.sys_id);


      gr.query();


      while(gr.next()){


              //if RITM is updated by SCTASK assigned to, don't push comments to work notes


              if (gr.assigned_to != ritmupdater)


                      gr.work_notes = current.comments;


              gr.update();


      }


View solution in original post

15 REPLIES 15

Michael Fry1
Kilo Patron

While we do push comments from SCTask to RITM (so Requester gets notified), we push Comments from RITM to Worknotes on SCTask but we check if the updater is the same person assigned to the SCtask. If they are, we don't send the comments to SCtask. Here's the script we use to check:




var ritmupdater = gs.getUserID();


     


      var gr = new GlideRecord('sc_task');


      gr.addQuery('request_item',current.sys_id);


      gr.query();


      while(gr.next()){


              //if RITM is updated by SCTASK assigned to, don't push comments to work notes


              if (gr.assigned_to != ritmupdater)


                      gr.work_notes = current.comments;


              gr.update();


      }


Hi Michael,



When you say "we do push comments from SCTask to RITM" is there already other OOB script(s) doing this?   If yes, what is the name of BR or script?   Don't want to replicate functionality.



Also, would you know when copying from Request Item to Task it is causing this behavior?   When I copy from Task to Request Item and/or Request the comments stay within Additional Comments/Work Notes journal 'Activity' stream area.


Capture.JPG


No out of the box script from SCTask to RITM, just saying we're doing the same thing.



As for 2nd question, it's sticking the comments in the middle of the screen?


Correct!   Two versions of the same comment.   One in the activity stream and one above.