- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 02:43 AM
I’m working on a requirement where we need to send an email notification from a task (Change) that includes the latest 3 work notes in the email body.
Has anyone implemented a similar solution? I’m looking for the best approach to achieve this—whether through a notification template, scripted email, or email script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 03:16 AM - edited 06-20-2025 03:21 AM
Hi @KARUNK,
By default, glide.email.journal.lines is set to 3 but that includes Additional Comments too.
Use this email script to retrieve last 3 lines of Worknotes.
Note: This will work on Record insert or update.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var work_note = new GlideRecord("sys_journal_field");
work_note.addEncodedQuery("element_id=" + current.sys_id + "^element=work_notes");
work_note.orderByDesc('sys_created_on');
work_note.setLimit(3);
work_note.query();
while (work_note.next()) {
var user = new GlideRecord("sys_user");
user.addQuery("email", work_note.sys_created_by);
user.query();
if (user.next()) {
template.print('<hr>');
template.print('<div style="display: flex; justify-content: space-between; align-items: center;">');
template.print('<span><b>' + work_note.sys_created_on + ' - ' + user.name + '</b></span>');
template.print('<span>(Work Notes (Internal))</span>');
template.print('</div>' + work_note.value + '<br>');
}
}
})(current, template, email, email_action, event);
Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 03:16 AM - edited 06-20-2025 03:21 AM
Hi @KARUNK,
By default, glide.email.journal.lines is set to 3 but that includes Additional Comments too.
Use this email script to retrieve last 3 lines of Worknotes.
Note: This will work on Record insert or update.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var work_note = new GlideRecord("sys_journal_field");
work_note.addEncodedQuery("element_id=" + current.sys_id + "^element=work_notes");
work_note.orderByDesc('sys_created_on');
work_note.setLimit(3);
work_note.query();
while (work_note.next()) {
var user = new GlideRecord("sys_user");
user.addQuery("email", work_note.sys_created_by);
user.query();
if (user.next()) {
template.print('<hr>');
template.print('<div style="display: flex; justify-content: space-between; align-items: center;">');
template.print('<span><b>' + work_note.sys_created_on + ' - ' + user.name + '</b></span>');
template.print('<span>(Work Notes (Internal))</span>');
template.print('</div>' + work_note.value + '<br>');
}
}
})(current, template, email, email_action, event);
Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 03:28 AM
No system property change required.
In your notification include this email script and it will show latest 3 work notes
I hope you are aware on how to include email script in email body
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
template.print('Latest 3 work notes <br/>');
var fieldName = 'work_notes';
var rec = new GlideRecord('sys_journal_field');
rec.orderByDesc('sys_created_on');
rec.addQuery('name', current.getTableName());
rec.addQuery('element', fieldName);
rec.addQuery('element_id', current.sys_id);
rec.setLimit(1);
rec.query();
if (rec.next()) {
template.print(rec.value);
}
})(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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 07:01 AM
Thank you for marking my response as helpful.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2025 09:53 PM
Hope you are doing good.
Did my reply answer your question?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2025 11:34 PM
Hi @Ankur Bawiskar I tried using this email script, but I'm only getting one work note populated instead of three. I changed rec.setLimit(1) to rec.setLimit(3), but it's still showing only one work note