Copy activity log from parent to task

andersn
Giga Contributor

Hi,

I was wondering if anyone had a quick tip on how to copy the activity log from parent to underlying tasks? Lets say you've been working on an incident and after a while find out you need to create a task and send to an external vendor. When I create the task i want all information from activity log to be updated on the tasks actiity log too..

1 ACCEPTED SOLUTION

I got it working using this BR:



var gr = new GlideRecord('incident');


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


      gr.query();


      if (gr.next()) {


              var comments = gr.comments.getJournalEntry(-1);


              current.comments = comments;


              //gs.addInfoMessage('Old log:' + comments);


      }


View solution in original post

2 REPLIES 2

kristenankeny
Tera Guru

Are you looking to grab the existing comments and copy them down or have all future comments added to the Incident copy to the task?



If existing comments, you should be able to include 'comments' in your script and put it into the 'comments' on your task.



If continuing to copy, you should create a Before Update business rule on your Incident table, with the condition "Additional comments" "changes". Then in the advanced tab script field, write a script similar to this (this one copies the comments from sc_task to the sc_req_item:



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



  var gr = new GlideRecord('sc_req_item');


  gr.get(current.request_item);


  gr.comments = current.comments;


  gr.update();



})(current, previous);


I got it working using this BR:



var gr = new GlideRecord('incident');


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


      gr.query();


      if (gr.next()) {


              var comments = gr.comments.getJournalEntry(-1);


              current.comments = comments;


              //gs.addInfoMessage('Old log:' + comments);


      }