Get Users from a List Collector and display their emails in an Email body

baraka
Tera Contributor

Hi,

I'm developing a form that will send an email notification once approved. The form has a list collector* variable. The email notification will need to display all users selected on the list collector along with their email addresses. The email notification I'm setting is part of the catalog item workflow. 

Since the list collector stores all users in one variable, how do I go about getting all users selected emails and then display them on the body of the email notification?

If I need to write an email script, please help with providing some examples.

Thank you

* the list collector references the sys_user table

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Since it is a reference field you need to query to get all username and email addresses

sample script

var users = current.variables.<listCollectorVariable>;

var userRec = new GlideRecord('sys_user');

userRec.addQuery('sys_id', 'IN', users.toString());

userRec.query();

while(userRec.next()){

template.print('User Name is:' + userRec.user_name + ' email address is: ' + userRec.email);

}

Mark Correct if this solves your issue and also mark 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

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Since it is a reference field you need to query to get all username and email addresses

sample script

var users = current.variables.<listCollectorVariable>;

var userRec = new GlideRecord('sys_user');

userRec.addQuery('sys_id', 'IN', users.toString());

userRec.query();

while(userRec.next()){

template.print('User Name is:' + userRec.user_name + ' email address is: ' + userRec.email);

}

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

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