List collector have to get email ton populate by user name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have a requirement to use a List collector and have the user that is selecteds email to populate by user name.
i can do it when it’s just a reference field and only one user can be selected. But multiple users can be selected, that’s why I’m using a list collector.
thank you in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
A List Collector stores multiple selected users as comma-separated sys_ids, so you cannot dot-walk like a normal reference field. You need to send those selected sys_ids to the server and return the emails.
You can solve this with a Catalog Client Script + GlideAjax.
Script include code
var GetUserEmails = Class.create();
GetUserEmails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmails: function () {
var userIds = this.getParameter('sysparm_user_ids');
var emails = [];
if (!userIds)
return '';
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', 'IN', userIds);
userGR.query();
while (userGR.next()) {
if (userGR.email) {
emails.push(userGR.email.toString());
}
}
return emails.join(', ');
},
type: 'GetUserEmails'
});
Catalog Client Script for AWS Account Request and Variable name is “list of users”
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
g_form.setValue('user_emails', '');
return;
}
var ga = new GlideAjax('GetUserEmails');
ga.addParam('sysparm_name', 'getEmails');
ga.addParam('sysparm_user_ids', newValue);
ga.getXMLAnswer(function(answer) {
g_form.setValue('user_emails', answer);
});
//Type appropriate comment here, and begin script below
}While tests in AWS Account Request
- User selects multiple users in List Collector
- Script runs on change
- Sends selected users to Script Include
- Fetches emails
- Then it automatically populates email field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Sorry you will have list collector and when user selects multiple users what should happen?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Darlene York ,
I dont think your requirement is feasible.
You can do one thing.
To display user emails from a List Collector, use an onChange Client Script paired with GlideAjax to fetch email addresses for selected users and populate them in a Multi-Line Text variable. The List Collector displays user names (from the sys_user table), while the script converts these into email addresses.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11 hours ago
Thank you, that does help. Would it be possible to get a sample script?
Thank you
