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

The list collection will only show Active users

Active users by default has notification setup to recieved

 

no Dice on the +

 

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);
}

Peter Williams
Kilo Sage

any other suggestions?

i am still struggling with this script

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);