- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I’m trying to automatically add all users from the RITM watch list to the CC field of an outbound email in ServiceNow, but they are not being added.
I created the following mail script and referenced it in my email template with ${mail_script:setCopyEmail}. The notification is triggered correctly and the main recipient receives the email, but no addresses appear in CC.
Mail script
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var mailList = current.watch_list || "";
if (!mailList) {
return;
}
var gr = new GlideRecord("sys_user");
gr.addEncodedQuery("sys_idIN", mailList);
gr.query();
var added = {};
while (gr.next()) {
var userMail = gr.getValue("email");
if (userMail && !added[userMail]) {
email.addAddress("cc", userMail);
added[userMail] = true;
}
}
})(current, template, email, email_action, event);
Email template:
${mail_script:generate_subject_detail}
${mail_script:show_close_notes_if_any}
${mail_script:setCopyEmail}
Request number: ${number}
Opening date: ${mail_script:formatted_opening_date}
Requester: ${mail_script:get_requester_dynamically}
Request summary:
${short_description}
${description}
${mail_script:detailed_request_information_en}
${mail_script:restart_computer_it_en}
Could someone point out what I might be missing, either in the mail script or in the way I’m calling it from the email template?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
update as this
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var mailList = current.watch_list.toString() || "";
if (!mailList) {
return;
}
var gr = new GlideRecord("sys_user");
gr.addActiveQuery();
gr.addEncodedQuery("sys_idIN" + mailList);
gr.query();
while (gr.next()) {
var userMail = gr.getValue("email");
if (userMail) {
email.addAddress("cc", userMail, gr.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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
update as this
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var mailList = current.watch_list.toString() || "";
if (!mailList) {
return;
}
var gr = new GlideRecord("sys_user");
gr.addActiveQuery();
gr.addEncodedQuery("sys_idIN" + mailList);
gr.query();
while (gr.next()) {
var userMail = gr.getValue("email");
if (userMail) {
email.addAddress("cc", userMail, gr.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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
@hrafael -
Try this code
OR
Root Cause (Why CC is Empty)
In ServiceNow:
Mail scripts referenced inside the email body/template cannot reliably modify email headers (To/CC/BCC).
By the time ${mail_script:setCopyEmail} is executed:
The email headers (To/CC/BCC) are already finalized
email.addAddress("cc", …) is silently ignored
That’s why:
Notification triggers
Main recipient receives the email
CC is empty
This is expected platform behavior, not a bug in your script.
Correct Ways to Add Watch List Users to CC
Option 1 (Best Practice): Use the Notification “CC” field
If this is an RITM (sc_req_item):
Open the Notification
In the Who will receive section
Set CC to:
Watch list
ServiceNow automatically resolves watch_list → user emails
No script needed
Supported by platform
Most reliable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @hrafael
Try this ,
