Email script for populating Opened by value in notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hello Team
I have a requirement in my current project where I need to send an email notification after approvals rejected so that I have created one email notification the approval table. In the notification body, I want to display the name of the person who rejected the HR case (i.e., the "Opened By" name), along with the HR case number.
However, I'm unable to find the fields for "Opened By", "HR Case No", and the name of the person who rejected the approval. Does anyone know how to write email script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @may13 ,
Please use the below email script..
(function runMailScript(current, template, email, email_action, event) {
var hrCaseGR = new GlideRecord('sn_hr_core_case'); // Replace with your HR case table name
hrCaseGR.get(current.hr_case); // 'current' is the approval record
// Print HR Case Number
template.print('<strong>HR Case Number:</strong> ' + hrCaseGR.getDisplayValue('number') + '<br/>');
// Print Opened By
template.print('<strong>Opened By:</strong> ' + hrCaseGR.opened_by.getDisplayValue() + '<br/><br/>');
// Find approver who rejected
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('sysapproval', current.sysapproval);
appr.addQuery('state', 'rejected'); // state that indicates rejection
appr.query();
if (appr.next()) {
template.print('<strong>Rejected By:</strong> ' + appr.approver.getDisplayValue() + '<br/><br/>');
}
template.print('Your HR case approval was **rejected**. Please review and take necessary actions.');
})(current, template, email, email_action, event);
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/