How to get the commentator and the comment when worknotes change

Alon Grod
Tera Expert

Hi,

 

Im trying to send a new comment on the worknotes using mail script but Im not getting the comment  and the commentator, instead Im getting a sys id and an empty comment.

This is my mail script:

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    var commentorName = event.parm1;
    var userGr = new GlideRecord('sys_user');
    userGr.addQuery('sys_id', commentorName);
    userGr.query();
    if (userGr.next())
        commentorName = userGr.name;
    var comment = current.comments.getJournalEntry(1);
    var commentTextIndex = comment.indexOf('\n');
    var commentMessage = comment.slice(commentTextIndex + 1, comment.length - 2);
    commentMessage = commentMessage.replace(/\n/g, '<br/>');
    // template.print('<div style="line-height: 24px;color:#181A1F;">');
    //     template.print('<div style="text-align: center; line-height:36px; padding-bottom: 24px;' +
    //         ' border-bottom: 1px solid #DADDE2;"><span style="font-size: 24px;">' +
    //         commentorName + ' added a comment to your request</span></div>');
    // template.print('<div style="font-size: 16px; padding-top: 24px; padding-bottom: 16px;">' +
    //    'היי ' + current.caller_id.first_name + ',</div>');
    //     template.print('<div style="font-size: 16px; padding-bottom: 16px; ">' +
    //         commentorName + '<span style="font-weight: 600">' +'</span>:</div>');
    //     template.print('<div style="font-size: 16px; font-weight: 600;">' + '"' + commentMessage + '"' + '</div>');
    template.print(commentorName + ": \"" + commentMessage + "\" ");
    //template.print('</div>');

})(current, template, email, email_action, event);

 

This is what im getting:

Screenshot 2023-07-27 at 7.57.59.png

12 REPLIES 12

@Ankur Bawiskar  hi I tried your script and now Im not getting anything at all (the last row should display comment and name of user that send the comment but its empty:

Screenshot 2023-07-27 at 8.31.51 1.png

@Alon Grod 

are you sure on these 2 things?

1) notification is on incident table

2) did you debug what came in comments value?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar  notification is on the incident table. I understood what was the problem with the user name and now Im getting it, but Im still not getting the comment value. It seems like this command does not get any value: 

    var comment = current.comments.getJournalEntry(1);

 

@Ankur Bawiskar  what is parm1 represents, i know that parm2 is the sys_id of the user that commented:

 

Screenshot 2023-07-27 at 8.49.44.png