Email Script bcc

Rishabh Dev Kha
Tera Contributor

Hi I have wrote an script for sending notification under bcc but when I am using below script blank is getting sent,can anyone help me

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

// Add your code here
if(!current.watch_list.nil()){
var watcherIds = current.watch_list.split(',');
for (var i=0; i< watcherIds.length; i++) {
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", watcherIds[i]);
user.addQuery("notification",2);
user.addQuery("email","!=","");
user.query();
if (user.next()){
email.addAddress('bcc', user.email, user.getDisplayValue());
}
else{
email.addAddress('bcc', watcherIds[i]);
}
}
}

})(current, template, email, email_action, event);

5 REPLIES 5

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

You mean recipeint list is empty? Are you sure you checked for values in BCC field & not To.

shloke04
Kilo Patron

Hi @Rishabh Dev Khare 

Please update your script as below, I have modified it as below and is working for me in my PDI:

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    if (!current.watch_list.nil()) {
        //get watch list addresses and add to cc
        var watcherIds = current.watch_list.split(",");

        //get user records
        var user = new GlideRecord("sys_user");
        user.addQuery("sys_id", watcherIds);
        user.addQuery("notification", 2);
        //email
        user.addQuery("email", "!=", "");
        user.query();

        while (user.next()) {
            //add to cc list    
            email.addAddress("bcc", user.email, user.getDisplayValue());
        }
    }

})(current, template, email, email_action, event);

Also to check make sure you add the column Blind Copied in your email log List Layout View to view this result as shown below:

find_real_file.png

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

Hi still when I preview email it shows blank:

 

find_real_file.png

Recipient list will not show up in preview. Check for the email log.

Also, the mail script you using is not for body its just for recipient list update.