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

In what way are you getting all the users that should be inserted in the CC (what value are we getting in here

current.variables.<all user to include incc>

). Are those users Active, have an email and are they notifications active?

its coming from a List collector

 

 

Can you make a screenshot of what you are using and a console log or something to see what you have in the list collector as data.

this is the code i am trying to use but not working 

 

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

Hi @Peter Williams ,
if all the IDs of the users for the CC are in this variable -  current.variables.cc_email, don't split it use just  current.variables.cc_email+''.

If the problem is not there gs.log() the data an see where the problem is.Hope that this helps you!

If the provided information answers your question, please consider marking it as Helpful and Accepting the Solution so other community users can find it faster.

All the Best,
Stefan