when an HR Agent clicks compose Email, automatically include the last 5 comments in workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
When an HR Agent clicks the out-of-the-box "Compose Email" action, the email body should automatically include the last 5 comments from the HR Case.
What I have tried:
Created an Email Client Template.
Added a Mail Script to retrieve the last 5 comments.
Referenced the Mail Script in the Email Client Template.
However, when I click Compose Email from HR Agent Workspace:
The Mail Script does not execute.
The email body does not populate the last 5 comments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
notification mail script does get trigger from email client template
here is the working logic
Seems something in your side is not configured properly or script is breaking
Email Script:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var fieldName = 'work_notes';
var arr = [];
var rec = new GlideRecord('sys_journal_field');
rec.orderByDesc('sys_created_on');
rec.addQuery('name', 'change_request');
rec.addQuery('element', fieldName);
rec.addQuery('element_id', current.sys_id);
rec.setLimit(5);
rec.query();
while (rec.next()) {
arr.push(rec.value.toString());
}
template.print('Latest 5 work notes are' + arr.toString());
})(current, template, email, email_action, event);
Email Client Template calling that Email Script:
Output:
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader