How can I capture comment made in ritm using email script?

Erica2
Tera Contributor

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);

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi @Erica2 

please use the short notation:

template.print(current.sysapproval.comments.getJournalEntry(1));

 Maik

View solution in original post

10 REPLIES 10

Wasn't sure anymore whether the "-1" would bring the latest comments on top.