Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Autopopulate multiple values based on Options selected in List Collector variable

suuriya
Tera Contributor

Hi Community,

 

I have a requirement, in catalog form i need to populate multiple value in multiline text variable based on the option selected in list collector variable.

So i have written a onchange client script and script include but only one value is getting displayed in multi line variable.

 

client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var getCI = g_form.getValue('select_print_groups').split(","); // list collector variable name
  var ga = new GlideAjax("Printer"); // script include name
   ga.addParam("sysparm_name","getApplication"); // script include function name
   ga.addParam("sysparm_sys_id",getCI); // pass values to script include
   ga.getXMLAnswer(parseResponse);
    function parseResponse(answer) {
        //alert(answer);
    g_form.setValue('printers_included_in_group',answer); // set the values to the field
    }
   
   
}
Script include:
var Printer = Class.create();
Printer.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApplication : function(){
        var CI = [];
        var sysId = this.getParameter('sysparm_sys_id'); // sysid of list collector values from client script
        gs.info("sysID==>"+sysId);
        var almAssetGr = new GlideRecord("u_kallik_site_codes_and_access_groups"); // glide the table which your using as list collector where the values stored
        almAssetGr.addQuery('sys_id', "IN", sysId);
        almAssetGr.query();
       while (almAssetGr.next()) {
         CI.push(almAssetGr.getValue('u_printer')); // pass the field name where you want to populate values on other field
               }
            return CI.join();
    },
    type: 'Printer'
});

FYI values will be shown in select print groups (list collector) based on value selected in select site name (lookup select) variable by
suuriya_3-1698232912224.png

 



suuriya_0-1698231084977.pngsuuriya_1-1698231115395.png

 

suuriya_2-1698232668831.png

 

But as of now only one value is getting populated if i select tampa zebra print group then all 3 printer values need to be populate.

 

And one more thing in select print group duplicate is getting as u can see 3 tampa zebra print group is there it should be only one 

 

How can we achieve this 

Thanks in advance

1 REPLY 1

Harsh_Deep
Giga Sage
Giga Sage

Hello @suuriya ,

 

In your client script

var getCI = g_form.getValue('select_print_groups').split(","); // list collector variable name

remove .split(",");

 

use this 

var getCI = g_form.getValue('select_print_groups')// list collector variable name

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.