How to get names/email address from List Collector for email notification

KayB2
Kilo Contributor

How do I get the email address of user from List Collector so I can send email notification to them via Workflow?

I tried this script but not working. Please help! 

 

//I named my list collector field choose_name

answer = [];
var user = current.variables.choose_name.split(',');
for (var i = 0; i < user.length; i++) {
var u = new GlideRecord('sys_user');
if (u.get(user[i])) {
answer.push = email.addAddress("user", u.email, u.getDisplayValue());

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kay,

you need an array to hold the sys_id and then use the answer variable

answer = [];

var emailSysId = [];
var user = current.variables.choose_name.split(',');
for (var i = 0; i < user.length; i++) {
var u = new GlideRecord('sys_user');

if (u.get(user[i])) {

emailSysId.push(u.sys_id.toString());

}

}

answer = emailSysId;

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Hello Ankur, 

Looks like variable value is not coming. gs.log result is undefined. Please see below.

 

find_real_file.png

 

 

KayB2
Kilo Contributor

I tried adding toString() to the var user and it looks like value(sys id) is coming. However, no emails were sent. 
Please see below snips. 

 

find_real_file.pngfind_real_file.png

KayB2
Kilo Contributor

Hello Ankur,

Good news! 

I replace emailSysId.push with answer.push(last line of script) and it works!

Emails are now being sent to all users selected from the List Collector. Fantastic! 

Thank you very much for helping me out! 

 

find_real_file.png

 

Regards,
Kay

RKerr
Tera Guru

Used this in Madrid and worked perfectly, the only modification necessary was adding .toString() to the var user=
THANK YOU

 

answer = [];


var emailSysId = [];
var user = current.variables.choose_name.toString().split(',');
gs.info("Users from variable are:"+user);
for (var i = 0; i < user.length; i++) {
var u = new GlideRecord('sys_user');


if (u.get(user[i])) {


emailSysId.push(u.sys_id.toString());


}


}


answer = emailSysId;