Add User in CC of an email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
3 weeks ago
Hello @may13 ,
Use this script according to your requirement,
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
email.addAddress('cc', L1_approval.email, 'L1_approval.name');
email.addAddress('cc', L2_approval.email, 'L2_approval.'name);
email.addAddress('cc', hr_employee.email, 'hr_employee.name');
})(current, template, email, email_action, event);
If my response helped mark as helpful and accept the solution..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @may13 ,
This might help you
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// L1 Approval
if (current.l1_approval) {
var l1User = current.l1_approval.getRefRecord();
if (l1User && l1User.email) {
email.addAddress('cc', l1User.email.toString(), l1User.getDisplayValue().toString());
}
}
// L2 Approval
if (current.l2_approval) {
var l2User = current.l2_approval.getRefRecord();
if (l2User && l2User.email) {
email.addAddress('cc', l2User.email.toString(), l2User.getDisplayValue().toString());
}
}
// HR Employee
if (current.hr_employee) {
var hrUser = current.hr_employee.getRefRecord();
if (hrUser && hrUser.email) {
email.addAddress('cc', hrUser.email.toString(), hrUser.getDisplayValue().toString());
}
}
})(current, template, email, email_action, event);
Hope it helps
-------------------------------------------------------------------------------------------------------------------------------------------------
If my response helped you, please mark it as helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 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
3 weeks 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
