How to Populate List collector values to the Multi line text variable

Aparna Gurav
Tera Contributor

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.

AparnaGurav_0-1740668519252.png

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
    },

 

6 REPLIES 6

@Aparna Gurav 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Aparna Gurav 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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