taking users of a list collector field in a email CC

Amit Dey1
Tera Contributor

Hi ,

I have a list collector field in a table , which is referencing to user table , my requirement is to add those users in a email cc , so how can we do this via email scripts or any other ways ?

 

 

Thanking you in advance...

1 ACCEPTED SOLUTION

mattystern
Kilo Sage

Hi @Amit Dey1 

 

This thread has details on using a list collector in a notification email script. Copying the script used in the thread here:

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

    // Add your code here
    if (!current.<manager_list_variable_name_goes_here>.nil()) {
        //get watch list addresses and add to bcc
        var watcherIds = current.<manager_list_variable_name_goes_here>.split(",");
        //get user records
        var user = new GlideRecord("sys_user");
        user.addQuery("sys_id", "IN", watcherIds);
        user.addQuery("email", "!=", "");
        user.query();

        while (user.next()) {
            //add to cc list    
            email.addAddress("cc", user.getValue('email'), user.getDisplayValue()); 	//Carbon Copy
            //email.addAddress("bcc", user.getValue('email'), user.getDisplayValue());	//Blind Carbon Copy
        }
    }
})(current, template, email, email_action, event);

 

Product documentation referenced in that post here. 

 

Hope this was helpful!

 

-Matt

View solution in original post

2 REPLIES 2

mattystern
Kilo Sage

Hi @Amit Dey1 

 

This thread has details on using a list collector in a notification email script. Copying the script used in the thread here:

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

    // Add your code here
    if (!current.<manager_list_variable_name_goes_here>.nil()) {
        //get watch list addresses and add to bcc
        var watcherIds = current.<manager_list_variable_name_goes_here>.split(",");
        //get user records
        var user = new GlideRecord("sys_user");
        user.addQuery("sys_id", "IN", watcherIds);
        user.addQuery("email", "!=", "");
        user.query();

        while (user.next()) {
            //add to cc list    
            email.addAddress("cc", user.getValue('email'), user.getDisplayValue()); 	//Carbon Copy
            //email.addAddress("bcc", user.getValue('email'), user.getDisplayValue());	//Blind Carbon Copy
        }
    }
})(current, template, email, email_action, event);

 

Product documentation referenced in that post here. 

 

Hope this was helpful!

 

-Matt

It worked Thanks