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

Mauricio Macha1
Giga Contributor

Nya,

Please check example below from  

https://docs.servicenow.com/bundle/kingston-servicenow-platform/page/script/server-scripting/reference/r_ExScptEmlNtfn.html

 

//email.addAddress(type, address, displayname);
    email.addAddress("cc","john.copy@example.com","John Roberts");
    email.addAddress("bcc","john.secret@example.com","John Roberts");


Thank you so much!! I've actually tried it using that document as a template for mine and it did not work either ... I'm really stumped on why it's not working. 

Abhijit4
Mega Sage

Hi,

If you are adding same user on To list and BCC list then system will not show that user in BCC list.

Could you please provide recipient configuration screenshot at notification level and example triggered email screenshot so that it will be clear for us to debug/understand issue further.

Please mark this as Correct or helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hello Abhijit! 

Thank you so much for your help to investigate this issue.  Please find below a screenshot of the notification tab: "Who will receive" and also an example of the triggered email as well.  Any help you can provide is GREATLY appreciated!!!

Notification configuration:

find_real_file.png

Notification itself (from Outbox):

find_real_file.png

shloke04
Kilo Patron

Hi,

Make sure to set the value of this Property "glide.email.test.user" to blank as shown below:

1) Navigate to Properties module by typing "sys_properties.LIST" as shown below:

find_real_file.png

2) Search for this property "glide.email.test.user" and make the value as Empty as shown below:

find_real_file.png

 

If "glide.email.test.user" property is set then ServiceNow only set the "To" Recipient in the Email Headers even if the configurations are for CC and BCC field over the script it will be disregarded. 

If this property is set to empty value then we set To / CC / BCC as well. Please empty this property to achieve populating CC and BCC.

Please refer the HI Article below for more details on this:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783517

 

Also do refer to below HI Article as well and see if this helps:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0830775

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

Regards,
Shloke

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

Regards,
Shloke