- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 04:32 AM
Hi Everyone,
I am defining an Email script to add the approver of a HR case in cc and bcc of a notification triggered by an Event in the Flow. Please find the script below. Current object is the Approval GlideRecord passed from the event.
var gr = new GlideRecord('sn_hr_core_case');
if (gr.get(current.sysapproval)) {
var approvalgr = new GlideRecord('sysapproval_approver');
approvalgr.addQuery('sysapproval', gr.sys_id);
approvalgr.query();
while (approvalgr.next()) {
if (approvalgr.approver.email) {
var emailString = approvalgr.approver.email.toString();
var displayName = approvalgr.approver.name;
email.addAddress("cc", emailString, displayName);
}
}
}
})(current, template, email, email_action, event);
I logged all the details using gs.info and everything is fine, except that cc and bcc are not being populated in Email logs.
when I run the same script through Background scripts, its throwing an error sayin that email is not defined
Please pour your Insights.
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 04:52 AM
Hi @Madhan007 ,
you script looks good it should work
cc and bcc will be populated in the copied and Blind Copied field of the email
you can also use this script but your script should work fine
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var approvalgr = new GlideRecord('sysapproval_approver');
approvalgr.addQuery('sysapproval', current.getValue('sysapproval'));
approvalgr.query();
while (approvalgr.next()) {
if (approvalgr.approver && approvalgr.approver.email) {
var emailString = approvalgr.approver.email.toString();
var displayName = approvalgr.approver.name;
email.addAddress("cc", emailString, displayName);
}
}
})(current, template, email, email_action, event);
in the background script context the email parameter is undefined so it will throw the error
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 04:41 AM
@Madhan007 verify below link for the reference: cc & bcc on email - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 04:50 AM
you can't test it from background script.
Points to check
1) are those users active and not locked out?
2) are those users having email address populated in user record?
3) are those users having notification preference enabled?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2025 06:53 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 04:52 AM
Hi @Madhan007 ,
you script looks good it should work
cc and bcc will be populated in the copied and Blind Copied field of the email
you can also use this script but your script should work fine
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var approvalgr = new GlideRecord('sysapproval_approver');
approvalgr.addQuery('sysapproval', current.getValue('sysapproval'));
approvalgr.query();
while (approvalgr.next()) {
if (approvalgr.approver && approvalgr.approver.email) {
var emailString = approvalgr.approver.email.toString();
var displayName = approvalgr.approver.name;
email.addAddress("cc", emailString, displayName);
}
}
})(current, template, email, email_action, event);
in the background script context the email parameter is undefined so it will throw the error
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya