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-05-2022 09:13 AM
Hello Shloke04 - I agree that this should not be at all possible 🙂 ... I'm not sure how/why it's happening. On the incident form itself, the watchlist field is not there. It "may" be added as an enhancement later so I wanted to account for it in that event. On the incident itself, I am only using my own personal email address in the customer field, so no other user email address should be added. (see screenshot).
Incident Customer Field:
Notification:
Outgoing Event:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 10:24 AM
Can you share your Notification script which you have configured to assist you further?
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 01:58 PM
Sure! Here is the script:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
if (!current.u_users.nil()) {
var watcherIds = current.u_users.split(",");
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", watcherIds);
user.addQuery("email", "!=", "");
user.query();
while (user.next()) {
email.addAddress("bcc", user.email, user.getDisplayValue());
}
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 06:23 PM
This looks correct to me. Are there any other Email Script getting called in this Notification.
Open your Notification form and then click on the Related Link "Show Notification Script" and see if there are any other script which is triggering this additional recipient:
After click on the above link, can you check and share what else you are having here?
Regards,
Shloke
Regards,
Shloke