Copy additional comments from requested item item to all catalog tasks.

SK41
Giga Guru

Hi,

I have a requirement where  i have  to copy the additional  comments from  requested  item to all the  catalog tasks.Once the   item  is  approved all  the comments after the RITM  is approved,  should  be  copied  to  each  and  every  catalog tasks.

How  can i achieve  that?

Thanks.

26 REPLIES 26

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Can you share what you've tried so far? Can you share where you are stuck? Can you share where exactly you need help with?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

asifnoor
Kilo Patron

Hi,

You can write an after BR on ritm table 

Filter conditions

Approval is approved

Script

//fetch your catalog tasks
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item",current.sys_id);
gr.query();
while(gr.next()) {
  //fetch ritm comments liek this
  var comments = current.comments.getJournalEntry(-1);
  //stores each entry into an array of strings
  var na = comments.split("\n\n");                        
  for (var i = 0; i < na.length; i++){
    gr.comments = na[i].toString();
    gr.update();
  }
}

Mark the comment as a correct answer and also helpful once worked.

filter condition is not  working and   using   getJournalEntry(-1);  copies every comment even if   one comment  is added,  it copies  all the  previous comments  again  and  again.

What  is the     purpose  of splitting the  comments here? KIndly,  let me know.

getJournalEntry(1) returns only the latest comment.

so if you want all comments after the approval, then do it like this.

In your BR

Filter conditions:

Approval is approved

AND

comments changes

Script

//fetch your catalog tasks
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item",current.sys_id);
gr.query();
while(gr.next()) {
    //fetch latest ritm comments liek this
    var comments = current.comments.getJournalEntry(1);
    gr.comments = comments.toString();
    gr.update();
}

whenever a new comment is added, this will update that comment into all your associated catalog tasks.

Mark the comment as a correct answer and also helpful once worked.