How to get the commentator and the comment when worknotes change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 09:58 PM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 10:56 PM
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?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 10:55 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 11:49 PM - edited 07-26-2023 11:53 PM
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:
Notification tabs :
Output:
Let me know if this helps, and if so please mark it as correct.
Thanks!