How to send an email to CC people through email script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2023 04:09 AM
As an Approver's Manager, I would like 1 approval escalation email to be sent on MOnday for all approvers on my team who have approvals that have aged more than 7 days
- 1 email per manager of with pending approvals > 7 days for their team
- Table in email with details/link
- Post to the activity stream that Approval Escalation Email was sent
Email Template:
To: Manager
CC: Approvers
Subject: ServiceNow Pending Approvals over 7 Days
Message:
Dear [Manager Name],
The following approvals have been open for more than 7 days. Please work with the approvers on your team to action as soon as possible. Thank you!
[Table with Approver Name, RITM # & Link, Requested For, Short Description, Approval Created Date, Calculated Age Field]
I written email script like below everything is working fine except CC part.- Please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2023 04:39 AM
Hi @sasipriya
Please try below code and let me know -
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Initialize the cc_users array as an empty array
var cc_users = [];
template.print('Dear ' + event.parm2 + ',');
template.print('The following approvals have been open for more than 7 days. Please work with the approvers on your team to action as soon as possible.');
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addEncodedQuery('sysapprovalSTARTSWITHritm^state=requested^sys_created_onRELATIVELT@dayofweek@ago@7');
approvalGR.query();
template.print('<table border="1px solid black">');
template.print("<tr bgcolor='#ddd' align='center'>");
template.print("</tr>");
template.print("<tr>");
template.print("<td><left><b>" + "Approver name" + "</b></left></td>");
template.print("<td><left><b>" + " RITM" + " </b></left></td>");
template.print("<td><left><b>" + "Requested For" + "</b></left></td>");
template.print("<td><left><b>" + "Short Description" + "</b></left></td>");
template.print("<td><left><b>" + "Approval Created Date" + "</b></left></td>");
template.print("<td><left><b>" + "Approval Age" + "</b></left></td>");
template.print("</tr>");
while (approvalGR.next()) {
if (approvalGR.approver.manager == event.parm1) {
// ... Your existing code ...
// Push the approver into the cc_users array
cc_users.push(approvalGR.approver);
}
}
// Join the cc_users array into a comma-separated string
var ccEmails = cc_users.map(function (user) {
return user.email.toString();
}).join(',');
// Add CC recipients to the email
email.addCC(ccEmails);
template.print("</tr>");
template.print('</table>');
})(current, template, email, email_action, event);
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar