copy catalog task activities to ritm

jameshamptontp
Kilo Contributor

Is there a script available that copies the worknotes entered on a catalog task back to the parent RITM record?   We are using the RITM record to provide status back to the users via the portal.

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi James,



Nothing out of the box, but you could create a business rule that does this easily enough.



Name: Copy task work notes to RITM


Table: Task (sc_task)


Insert: checked


Update: checked


When: After


Advanced: checked


Condition: Work notes Changes (or in the condition field: current.work_notes.changes())


Script:


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



  var gr = new GlideRecord('sc_req_item');


  if (gr.get(current.parent)) {


      gr.work_notes = current.work_notes;


      gr.update();


  }


})(current, previous);



You said work notes. Change to 'comments' where appropriate if that's what you meant.


View solution in original post

24 REPLIES 24

Thanks Joshua. You are correct. The BR is firing. ==> indicates it entered the BR, <== means it exited.



Try this to copy the work notes on line 5... I didn't see it before, sorry.



        gr.work_notes = current.work_notes.getJournaleEntry(1);


https://lh3.googleusercontent.com/-KydYhrYXdW4/VRHfIJwE5FI/AAAAAAAAAB8/pvn3LkNCYws/w506-h750/Like%2BA%2BGlove-a%2521.jpg


I'm getting some extra string timestamp data but i should be able to substring that out without issue.



Thanks.


Pardon my typo. I hope you caught it. I had an extra 'e' on getJournalEntry()



gr.work_notes = current.work_notes.getJournalEntry(1);


I did sir. Since I doubt I'm the only person who'll want to do this in Helsinki Patch 4, I've included the updated code that is working for me now (strips out the system generated gobbley gunk):



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


     


      var gr = new GlideRecord('sc_req_item');


      if (gr.get(current.request_item)) {


             


              // Initialize Variables to be Used


              var tempnote, n, length, goodnote = '';


             


              // Put the Most Recent Work Note into a temporary variable


              tempnote = current.work_notes.getJournalEntry(1);


             


              // Grab the position of the last part of the string in the system generated timestamp/etc


              n = tempnote.lastIndexOf('(Work notes)') + 13;


             


              // Determine that length of the string


              length = tempnote.length;


             


              // Slice out the system generated timestamp/etc (start of timestamp to end of string)


              goodnote = tempnote.slice(n,length);


             


              // Put the cleaned up version of the work notes into the RITM


              gr.work_notes = goodnote;


             


              // Update the RITM record.


              gr.update();


      }


     


})(current, previous);



Hopefully others can find this to be helpful.



Thanks again Chuck. I owe you a bow-tie.


A slight issue.



When the final task is closed it's not automatically changing the state to 'Closed Complete'. I'm guessing this update is conflicting with the system behavior for some reason. Any ideas?