Copy additional comments from requested item item to all catalog tasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2021 12:03 AM
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.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2021 12:09 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2021 12:19 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2021 12:26 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2021 12:42 AM
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.