The CreatorCon Call for Content is officially open! Get started here.

Scripting Help- How to script an Email Script to BCC

Su522
Kilo Sage

Can I please get some help scripting an Email Script to bcc the "Assigned To" 

 

Here is my current script that is not working:

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

// This works:
//    email.addAddress("bcc", "abel.tuter@example.com", "Abel Tuter");

//This is Not working:
// Get Assigned PM address and add to BCC
    var assignedTo = current.u_assigned_to;

// Get user record
    var user = new GlideRecord('sys_user');
    user.addQuery("sys_id", assignedTo);
    user.addQuery("notification", 2);
    user.query();

// Add to BCC list    
    email.addAddress("bcc", user.email, user.getDisplayValue());

})(current, template, email, email_action, event);
1 ACCEPTED SOLUTION

SN_Learn
Kilo Patron
Kilo Patron

Hi @Su522 ,

 

Try the below:

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

// This works:
//    email.addAddress("bcc", "abel.tuter@example.com", "Abel Tuter");

// Get Assigned PM address and add to BCC
    var assignedTo = current.u_assigned_to;

// Get user record
    var user = new GlideRecord('sys_user');
    user.addQuery("sys_id", assignedTo);
    user.addQuery("notification", 2);
    user.query();
   while(user.next()){
// Add to BCC list    
    email.addAddress("bcc", user.getValue('email'), user.getValue('name'));
}
})(current, template, email, email_action, event);

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

2 REPLIES 2

SN_Learn
Kilo Patron
Kilo Patron

Hi @Su522 ,

 

Try the below:

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

// This works:
//    email.addAddress("bcc", "abel.tuter@example.com", "Abel Tuter");

// Get Assigned PM address and add to BCC
    var assignedTo = current.u_assigned_to;

// Get user record
    var user = new GlideRecord('sys_user');
    user.addQuery("sys_id", assignedTo);
    user.addQuery("notification", 2);
    user.query();
   while(user.next()){
// Add to BCC list    
    email.addAddress("bcc", user.getValue('email'), user.getValue('name'));
}
})(current, template, email, email_action, event);

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Su522
Kilo Sage

@SN_Learn 

That worked!!! Thank you so much!!