Add User in CC of an email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I have a requirement in my current project where I need to create an email script in ServiceNow. In the User table, I have three custom fields: L1 Approval, L2 Approval, and HR Employee. I need to include the users from these fields in the CC section of a notification. Could you please provide the email script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
since your notification is on HR Profile use this
-> you need to dot walk to user field and then get the details
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
email.addAddress('cc', current.user.L1_approvalField.email.toString(), current.user.L1_approvalField.getDisplayValue());
email.addAddress('cc', current.user.L2_approvalField.email.toString(), current.user.L2_approvalField.getDisplayValue());
email.addAddress('cc', current.user.HR_EmployeeField.email.toString(), current.user.HR_EmployeeField.getDisplayValue());
})(current, template, email, email_action, event);
💡 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 || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6m ago
Hi @may13 ,
Hope you are doing well.
You need to create a email script first and need to add it in the Email notification to make it work.
So, please follow the steps below to make it work .
Step - 1 :
1. go to system notification > email > Notification Email Script.
2. Create a new script named : email_CC.
Code :
(function runMailScript(current, template, email, email_action, event) {
// Helper function to safely add CC
function addCC(field) {
if (field && field.email) {
email.addAddress('cc', field.email.toString(), field.getDisplayValue());
}
}
// Attempt to add CC for each field
addCC(current.user.L1_approvalField);
addCC(current.user.L2_approvalField);
addCC(current.user.HR_EmployeeField);
})(current, template, email, email_action, event); Step - 2 :
- Open the Notification: Navigate to System Notification > Email > Notifications and select your desired notification record.
- Insert the Script Call: In the Message HTML field (within the What it will say tab), place the following line anywhere in the body:
- ${mail_script:email_cc}
- Verify Configuration: Ensure the Advanced view is enabled on the notification so the system properly processes the mail script during the email generation phase.
If my response has helped you, kindly mark it as helpful and accept the solution.
Regards,
Sagnic
