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

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

Hello Ankur, 

Thanks for your script, i tried it but still not sending email notifications to the selected names on the right. Please see below snips.

 

Hello Ankur,

 

Thanks for your script, i tried it but still not sending email notifications to the selected names on the right. Please see below snips.

find_real_file.png

find_real_file.png

 

Thanks, 
Kay

Hi Kay,

Can you add log statement and check whether variable value is coming or not?

var user = current.variables.choose_name.split(',');

gs.log("Users from variable are:"+user);

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