- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 08:22 PM
Hello,
We have a notification that triggers on the sysapproval_approver table. If a comment is added to the RITM record, we would like to capture it in the notification. We have tried the following code, but it did not work. Can someone please help? Thank you.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.request_item)) {
// 'ritm' now contains the related RITM record
var comments = [];
var commentGr = new GlideRecord('sys_journal_field');
commentGr.addQuery('element_id', ritm.sys_id);
commentGr.addQuery('element', 'comments');
commentGr.query();
while (commentGr.next()) {
comments.push(commentGr.value);
}
template.print(commentGr.value);
}
})(current, template, email, email_action, event);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 09:12 PM
Hi @Erica2
please use the short notation:
template.print(current.sysapproval.comments.getJournalEntry(1));
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 09:23 PM
Hi @Erica2
you don't need your code. Replace everything with what I have provided.
And are you really sure that the comment has been added to RITM record? In most of the cases, users will add a comment on the sysapproval_approver table.
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 09:47 PM
Thank you so much for your help @Maik Skoddow.
This is for my understanding. If a comment was added to the RITM record, as shown in the screenshot below, does this mean it was added to the sc_req_item table or the sysapproval_approver table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 09:55 PM
Hi @Erica2
thanks for sharing the screenshot and based on that information I can see the comment was added to the RITM.
So my provided line of code should work for you.
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 10:03 PM
You are very welcome @Maik Skoddow
Your provided code works well; however, it is currently printing only the latest comment added. Could you please help modify the code to print all comments, listing the latest one at the top?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 10:14 AM
Thank you again for helping @Maik Skoddow
I was able to get all comments printed and listing the latest one at the top. Here is the screenshot incase someone is looking for the same issue.