copy sctask comments to ritm

nameisnani
Mega Sage

Hi Team ,

 

can anyone please help me on this requiement .

 

Ony for particular catalog item ' Snow Support ' 

 

whenever sctask worknotes is updated the same comments should copy in ritm additinal comments . 

 

how to configure , can any one please help me .

 

@Ankur Bawiskar  Please help me here 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@nameisnani 

you can use after update business rule on sc_task

Condition: Work notes Changes && current.request_item.cat_item.name == 'Your Item Name'

Script:

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

    // Add your code here
    var ritm = current.request_item.getRefRecord();
    ritm.work_notes = current.work_notes.getJournalEntry(1);
    ritm.update();

})(current, previous);

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

12 REPLIES 12

@Ankur Bawiskar 

nameisnani_0-1754287135249.png

nameisnani_1-1754287180844.png

 

 

while doing testing 

 

i have attached - attachment in sctask - but is not copied to assiocated ritm @Ankur Bawiskar 

 

could u please hlep me here what was the issue here 

@nameisnani 

I informed to use after insert business rule on sys_attachment

AnkurBawiskar_0-1754290236107.png

 

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

kaushal_snow
Mega Sage

Hi @nameisnani ,

 

Good day !!

 

Create an After (Update) Business Rule on sc_task, and in when to run in first tab, select trigger only when Work Notes change AND the parent RITM is the specific catalog item “Snow Support”...

 

(function executeRule(current, previous) {
  if (!current.work_notes.changes()) return;
  var ritm = new GlideRecord('sc_req_item');
  if (!ritm.get(current.request_item) ||
      ritm.cat_item.toString() != 'sys id of catalog item')
    return;
  var wn = current.work_notes.getJournalEntry(1);
  if (!wn) return;
  var prev = ritm.comments.getJournalEntry(1);
  if (prev && prev.indexOf(current.sys_id) > -1) return;

  ritm.comments = 'From ' + current.number + ':\n' + wn + '\n(via task ' + current.sys_id + ')';
  ritm.update();
})(current, previous);

 

Additionally, you can use flow designer to achieve the same task...

 

Give it a try and let me know...

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/