how do i pass multiple recipients in parm1 email notifications

reginabautista
Kilo Sage

Hi How do i pass multiple recipients in parm1 parameters for the eventQueue? is it really necessary to pass the name of the recipient in parm2? Any ideas would be greatly appreciated. Thanks

var rec;

  var nm;

  var sIncl = new PIRGlobal();

  var isRMPM = sIncl.isRMPM();

  if(isRMPM){

  rec = current.opened_by;

  nm = current.opened_by.name;

  }else{

  rec = current.u_gatekeeper;

  nm = current.u_gatekeeper.name;

  }

  gs.log('rec= '+rec+' nm= '+nm);

  //added by Regina: Event to be used in sending notifications for Cancelled PIRs

  gs.eventQueue("pir.cancel.request", current,rec,nm);

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Regina,


You can pass multiple values separated by a comma.   The email notifications just need a comma separated list of user sys_id's and you don't need to pass the name unless you want them to show up in the email to line.   If you don't pass it, then just the email address will be present.   Here is some example code to get a list of users and create an array that you can then pass to an event:



var userList = [];


var userRec = new GlideRecord("sys_user");


userRec.addEncodedQuery(YOUR-ENCODED-QUERY);


userRec.query();


while (userRec.next()) {


      if (userList.toString().indexOf(userRec.sys_id) == -1) {


              userList.push(userRec.sys_id + "");


      }


}


gs.eventQueue("EVENT-NAME", current, userList.toString());



In my example code, emails will be in parm1


View solution in original post

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Regina,



You could json encode an object and pass it in the parameter, then use a mail script in the notification to set the addresses.



Mini-Lab - Events: Passing Objects


Mail script API


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Regina,


You can pass multiple values separated by a comma.   The email notifications just need a comma separated list of user sys_id's and you don't need to pass the name unless you want them to show up in the email to line.   If you don't pass it, then just the email address will be present.   Here is some example code to get a list of users and create an array that you can then pass to an event:



var userList = [];


var userRec = new GlideRecord("sys_user");


userRec.addEncodedQuery(YOUR-ENCODED-QUERY);


userRec.query();


while (userRec.next()) {


      if (userList.toString().indexOf(userRec.sys_id) == -1) {


              userList.push(userRec.sys_id + "");


      }


}


gs.eventQueue("EVENT-NAME", current, userList.toString());



In my example code, emails will be in parm1


Worked like a charm. Thanks Michael!


Hi Michael,

 

Why is needed to add the + "" when you are creating the array?

 

Thanks