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 09:59 PM
the screenshot shows some other language.
Do you want the name of the user and the comments value?
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:17 PM
@Ankur Bawiskar yes, as you can see in the last row im getting an empty comment inside " " + sys_id instead of getting the name of user and comment value inside ""
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 10:23 PM
@Ankur Bawiskar what am i doing wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 10:24 PM
something like this should work and should show latest comment and who added that
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var value = current.comments.getJournalEntry(1);
var str = value.split(' - ')[1];
var commentorName = str.split(') ')[0] + ')';
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
var commentMessage = value.replace(dateRE, '');
template.print(commentorName + ": \"" + commentMessage + "\" ");
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader