- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 11:29 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 09:44 PM - edited 09-07-2023 11:53 PM
I have tried with List Collector in Catalog Client Script to fetch the email ID of users and shows in the text field below
Here is the code (you can change it according to your requirements)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var traineesNames = g_form.getValue('select_trainee'); // 'select_trainee' is the backend name of the List Collector
var trainees = traineesNames.split(',');
var traineeEmails = [];
for(var i=0;i<trainees.length;i++){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',trainees[i]);
gr.query();
while(gr.next()){
traineeEmails.push(gr.email);
}
}
g_form.setValue('trainees_email_id',traineeEmails); // 'trainees_email_id' is the back end name of the text field
}
Please give me correct and helpful, if my answer helps to your requirement.
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 11:46 PM
You can use "g_form.getValue('BACKEND_NAME_OF_LIST_COLLECTOR')"
It will return the sys_ids of selected items.
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2023 12:57 AM
Hi @Snehal13 ,
generally list collector will return sys_id with comma seprated values. You can fetch the values from the list collector field by using g_form.getValue(name_of_field_here); > this will return the comma seprated sys_id which you can pass it to server side and perform operations on those sys_id.
I guess you question is incomplete can you please share the complete requitement to know what your trying to achive ?
i hope this helps,
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2023 01:43 AM - edited 09-03-2023 01:44 AM
var listCollectorValue = g_form.getValue('list_collector_field_name');
if (listCollectorValue) {
var sysIds = listCollectorValue.split(',');
var displayValues = [];
// Loop through each sys_id and fetch its display value
for (var i = 0; i < sysIds.length; i++) {
var sysId = sysIds[i].trim(); // Trim to remove any extra spaces
var displayValue = g_list.getDisplayValue(sysId);
if (displayValue) {
displayValues.push(displayValue);
}
}
if (displayValues.length > 0) {
var displayString = displayValues.join(', ');
}
}
})();
mark helpful if it helps to solve your problem
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 09:44 PM - edited 09-07-2023 11:53 PM
I have tried with List Collector in Catalog Client Script to fetch the email ID of users and shows in the text field below
Here is the code (you can change it according to your requirements)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var traineesNames = g_form.getValue('select_trainee'); // 'select_trainee' is the backend name of the List Collector
var trainees = traineesNames.split(',');
var traineeEmails = [];
for(var i=0;i<trainees.length;i++){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',trainees[i]);
gr.query();
while(gr.next()){
traineeEmails.push(gr.email);
}
}
g_form.setValue('trainees_email_id',traineeEmails); // 'trainees_email_id' is the back end name of the text field
}
Please give me correct and helpful, if my answer helps to your requirement.
Thank you
G Ramana Murthy
ServiceNow Developer