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

Adding Multiple users from a List Collector Variable to the CC in an Email Script

Peter Williams
Kilo Sage

I am not sure why ServiceNow doesn't have an option to add users to the CC instead of scripting it out but i need help 

 

I have a List Collector on my form where users can add more than one person to the CC of the email that gets sent out

 

what i am having issues is, to get all the user added to the CC. i know how to add one using the email scripts using a Single line text variable but i need to now how to script it for a List collector.

 

email.addAddress("cc", current.variables.ccemail.email, ccemail); 

 

i have look at options like putting it into an Array and using a For loop in the script but it doesnt seem to work

 

Please Help..

 

1 ACCEPTED SOLUTION

Peter Williams
Kilo Sage

i got the script to work now with this alternation

 

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

    var grUsers = new GlideRecord('sys_user');
    grUsers.addQuery('sys_id', "IN", current.variables.cc_email);
    grUsers.query();
    while(grUsers.next()) {
        email.addAddress("cc", grUsers.email.getDisplayValue()+'', grUsers.name+'');
template.print(grUsers.email.getDisplayValue()+ grUsers.name);
}

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

View solution in original post

17 REPLIES 17

tried to add it to the logs but nothing is appearing in it

i tried a simple tempate.print and getting this results

email: undefined name: undefined
email: undefined name: undefined
email: undefined name: undefined

 

however when i do current.variables.cc_email it displays their actual names

 

 

what is the code you are using in the template.print and what is the code you are using in the CC mail script 

i have re-worked the code and now showing the email address along with their names when printing it out

 

var grUsers = new GlideRecord('sys_user');
    grUsers.addQuery('sys_id', "IN", current.variables.cc_email);
    grUsers.query();
    while(grUsers.next()) {
        email.addAddress("cc", grUsers.email.getDisplayValue(), grUsers.name.getDisplayValue());
template.print(grUsers.email.getDisplayValue()+ grUsers.name);
}
 
however they are not appearing in the CC still

Have you checked if they are active users? And if they have their notifications turned on?
Try adding +'' after each of  grUsers.email.getDisplayValue(), grUsers.name.getDisplayValue(), because it might return an object.