- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2020 02:18 AM
Hi,
I have a catalog item with a list collector variable. It's listing all the users in the sys_user table. I want it to collect the email addresses of all the users selected.
I thought this could be done by adding something into the "reference qual" or "Variable Attributes" fields, but I have so far been unable to find a way.
Any ideas?
Many thanks,
Mark.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2020 03:12 AM
Hi
Have you tried onChange client script and script include to achieve this?
If my answer helped you in any way, please then mark it correct and helpful.
Kind regards,
Manas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2020 03:03 AM
Hi Mark,
You can have a look on the below thread with similar requirement.
https://community.servicenow.com/community?id=community_question&sys_id=37e89dfddbfd630011762183ca96197f
Kindly mark my answer as Correct and helpful based on the Impact.
Regards,
Alok

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2020 03:04 AM
The list collector will only hold the sys_ids of the records selected. You would have to use the sys_id and query the table to get the required values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2020 03:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2020 06:03 AM
Hi Manas,
Thank you for your reply. This all feels a bit beyond me at the moment, but hopefully I will get there.
So, I'm getting an error message, so I'm triggering something, but obviously I'm not there yet.
To confirm what I'm doing...
I've gone to System Definition > Script Includes, and created a new script called "GetEmails". I've entered the following script. I've also ticked the "Client callable" box, and made it accessible from "All application scopes".
---
var GetEmails = Class.create();
GetEmails.prototype = Object.extendsObject(AbsractAjaxProcessor, {
getEmails: function()
{
var users = this.getParameter('sys_ids');
var emails = [];
var userRec = new GlideRecord('sys_user');
userRec.addQuery('sys_id', 'IN', users.toString());
userRec.query();
while(userRec.next()){
emails.push(userRec.email.toString());
}
gs.log(emails);
return emails.join();
},
type: 'GetEmails'
});
---
I've then gone to my form via "Maintain Items", and under the "Catalog Client Scripts" tab, created a new script called "Get Email Address". I've entered the following script. I've selected the variable name I want from the drop down list.
---
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetEmails');
ga.addParam('sysparm_name', 'getEmails');
ga.addParam('sys_ids', newValue);
ga.getXML(callBack);
}
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
---
The result from this is that when I open the form and click on the field in question, a list of names appear. When I select one, the whole screen greys out, and an error box appears which reads, "null", with an OK button. I can click ok, and select another name, and the same error box appears each time.
What do you think I have done wrong?
Kind Regards,
Mark.