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

Nya Valdez1
Tera Contributor

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.

find_real_file.png

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);
18 REPLIES 18

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:

find_real_file.png

Notification:

find_real_file.png

Outgoing Event:

find_real_file.png

Can you share your Notification script which you have configured to assist you further?

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

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);

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:

find_real_file.png

After click on the above link, can you check and share what else you are having here?

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke