Notification email script not working - could really use some help!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2022 04:58 PM
Hello SN Developer Community!!
I have a requirement to send all external notifications to users on the email "bcc" field, rather than the "to" or "cc" field. The notifications are running against a custom table (u_operational_mechanical_incident) where there are custom incident forms and based on one field on each form called "Customers" (u_users) - please see screenshot below.
I have 3 notifications for Urgent / High incidents that have the mail script (copied below) added to the body of the email(s) - but the notifications are still listing the customers out on the "To" field, rather than the "Bcc" field. Can anyone please tell me what I'm doing wrong here?
(function runMailScript( /*GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /*Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var user = new GlideRecord("u_operational_mechanical_incident");
user.addQuery("u_users", current.getUniqueValue());
user.addQuery("email", "!=", "");
user.query();
while (user.next()) {
email.addAddress("bcc", user.getValue('email'), user.getValue('name'));
}
})(current, template, email, email_action, event);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2022 05:31 PM
email.addAddress("bcc","john.secret@example.com","John Roberts");
should be
email.addAddress("bcc", user.email, user.getDisplayValue());
per documentation here
https://docs.servicenow.com/bundle/rome-servicenow-platform/page/script/server-scripting/reference/r_ExScptEmlNtfn.html?cshalt=yes

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2022 06:15 PM
Thank you so much Bammer, I tried it that way also but for some reason the recipient list is still appearing on the "To" field rather than the "bcc" field. Do you have any other suggestions that I might be able to try? Please advise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2022 05:47 PM
HI,
Try this script :
(function runMailScript( /*GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /*Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var user = new GlideRecord("u_operational_mechanical_incident");
user.addQuery("u_users", current.getUniqueValue());
user.addQuery("email", "!=", "");
user.query();
while (user.next()) {
email.addAddress("cc", user.email, user.getDisplayValue());
}
})(current, template, email, email_action, event);
I hope the answer helps, You can thank me by Marking the answer ✅ Correct or ???? Helpful.
Thanks,
MF Sohail Khilji.
LinkedIn > https://www.linkedin.com/in/mf-sohail-khilji/
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2022 06:13 PM
Thank you so much for your reply Sohail ... I tried it that way, but the notifications are still going through with the recipients on the "To" field rather than the "Bcc" field - any other thoughts? Please advise.