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

@Alon Grod 

that should not be having any dependency

with current.comments.getJournalEntry(1) it would anyhow give latest comments and show the name of the user.

Did you add logs and see in my email script?

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

Prince Arora
Tera Sage
Tera Sage

@Alon Grod 

 

Can you please print this line:

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

 

Also please make sure, you are putting the comments only (Not worknotes).

 

and trace in the logs 

Nishita Padwal
Tera Contributor

Hello @Alon Grod -

 

I tried your requirement on my PDI. Can you check and verify if you are folloowing the same?

Posting the screenshots:

 

Business rule:

BR1.png

BR-Script-2.png

 

Notification tabs :

Notification-Conditions.png

Notification-Who will recieve.png

Notification-What will it contain.png

 

Output:

Output.png

 

Let me know if this helps, and if so please mark it as correct.

 

Thanks!