How do i remove user's name from additional comments in a notification sent on email?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 05:11 AM
Hi,
I cant fint any easy documentation on how to edit user's name on additional comment, when its sent with a notification. Is it possible to hide or remove user's name?
I can see that we are using an Email-template on the notification.
Hopefully someone can help me with this problem. Thank you!
Best regards,
Long
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 07:03 AM
Hi Long,
Indeed as you mentioned there is no way to do it with just showing the ${comments} field, as it will always include the created date/time and the users name.
What you would have to do is create a mail script (see docs) and retrieve the last comment(s) via the mail script instead.
Via the mail script you would have the possibility to specify what you need.
Note that you would have to be familiar with scripting in ServiceNow and try to understand what it does to be able to make appropriate modifications for your table, fields an desired results. 🙂
For example;
You could create a mail script called 'GetLastCommentOnly'
Then instead of using ${comments} you would use ${mail_script:GetLastCommentOnly} in your email notification.
Your mail script could look something like this:
Option 1) Retrieve the comment directly from the table; the created time and the comment value:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var journalEntry = new GlideRecord('sys_journal_field');
journalEntry.addQuery('element_id',current.sys_id);
journalEntry.addQuery('name','incident');
journalEntry.orderByDesc('sys_created_on');
journalEntry.query();
if (journalEntry.next()) {
template.print(journalEntry.sys_created_on + '\n' + journalEntry.value );
}
})(current, template, email, email_action, event);
If your comment would look like
2022-03-07 15:47:25 - Fernando (Additional comments) test
It would now include it in the email as;
2022-03-07 14:47:25 test
Option 2) Get the latest comment via getJournalEntry, but use Regex to remove the datetime and name so that you only have the comment:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var commentValueOnly = current.comments.getJournalEntry(1).match(/\n.*/gm).join("\n");
template.print(commentValueOnly);
})(current, template, email, email_action, event);
If your comment would look like
2022-03-07 15:47:25 - Fernando (Additional comments) test
It would now include it in the email as;
test
Hope this helps you further in your investigation and options.
Kind regards,
Fernando
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 07:10 AM
Hi,
you need to use email script for this
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader