How to Populate List collector values to the Multi line text variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 07:06 AM
Hello Team,
I need your help. I’m trying to copy the value from a list collector to a multiline text variable, I attempted with the client script and script include but it's not working.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
// Get the list collector values (comma-separated sys_ids)
var listCollectorValues = g_form.getValue('ad_group_members'); // Change this ID
if (listCollectorValues) {
var ga = new GlideAjax('SPR_Repo'); // Call Script Include
ga.addParam('sysparm_name', 'getNames');
ga.addParam('sysparm_ids', listCollectorValues);
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('list_collectors_names', response); // Change this ID
}
});
}
}
getNames: function() {
var userIds = this.getParameter("sysparm_ids");
gs.log('User IDs:', userIds); // Debug statement
if (!userIds) return '';
var userNames = [];
var idsArray = userIds.split(',');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', idsArray);
gr.query();
while (gr.next()) {
userNames.push(gr.getValue('name')); // Get full name
}
gs.log('User Names:', userNames); // Debug statement
return userNames.join('\n'); // Join with line breaks
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 07:21 AM
I think you don't need this line in your script include:
var idsArray = userIds.split(',');
Replace your script include function with below code and try.
getNames: function() {
var userIds = this.getParameter("sysparm_ids");
gs.log('User IDs:', userIds); // Debug statement
if (!userIds) return '';
var userNames = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', userIds);
gr.query();
while (gr.next()) {
userNames.push(gr.getValue('name')); // Get full name
}
gs.log('User Names:', userNames); // Debug statement
return userNames.join('\n'); // Join with line breaks
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 08:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 08:22 AM
getNames: function() {
var userIds = this.getParameter("sysparm_ids");
gs.log('User IDs:', userIds); // Debug statement
if (!userIds) return '';
var userNames = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', userIds);
gr.query();
while (gr.next()) {
userNames.push(gr.getValue('name')); // Get full name
}
gs.log('User Names:', userNames); // Debug statement
return userNames.join('\n'); // Join with line breaks
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 07:40 AM
use this
getNames: function() {
var userIds = this.getParameter("sysparm_ids");
gs.log('User IDs:', userIds); // Debug statement
if (!userIds) return '';
var userNames = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', idsArray);
gr.query();
while (gr.next()) {
userNames.push(gr.getValue('name')); // Get full name
}
gs.log('User Names:', userNames); // Debug statement
return userNames.join('\n'); // Join with line breaks
},
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader