Populate values based on selection of options in list collector field

suuriya
Tera Contributor

Hi,

 

I have a requirement, in catalog form there are 3 fields namely Select site name, Select Print groups and Printers included in group (FYI select print groups is dependent on select site name field) If any value is selected in select Print groups field, then printers' details need to populate in printers included in group field.

 

Select Print groups field is a list collector so multiple options can be selected...For example if i select "print group - tampa" in Select Print groups field then TAM-DV, TAM- SAT, Barcode these values need to be populate in Printers included in group field....likewiswe if i select more than 1 value in list collector field then respective printers details need to be populate in the field

 

Example

suuriya_0-1698179451858.png

in this case 2 values selected so AM-DV, TAM- SAT, Barcode and zebra tear, zebra 00 zebra 10 these values need to be populate in printers included in group field

 

There are multiple options present in select print groups so based on selecting each option a set of printer details need to populate in printers field....I have list of printer details related to each group in excel.

 

How can we achieve this.....please help me with entire onchange script.

 

Thanks in advance

13 REPLIES 13

Hi @suuriya replace the below bolded line. Make sure the field name from select_print_groups table is correct in script include .

getApplication : function(){
var CI = [];
var sysId = this.getParameter('sysparm_sys_id'); // sysid of list collector values from client script
var almAssetGr = new GlideRecord("select_print_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')); // here you need to get the printer value
}
return CI.join();
},

Regards
Harish

Hi @Harish KM ,

 

I replace the line but it is showing as null

suuriya_0-1698221325424.png

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
        var almAssetGr = new GlideRecord("select_print_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'
});

Hi @suuriya 

Can you put logs here and check what value your getting? The below sys id should match the record in your printer table which you select on list collector variable and then in this table you need to get the value of the field which you want to auto populate

var sysId = this.getParameter('sysparm_sys_id'); // sysid of list collector values from client script

gs.info("sysID==>"+sysId);

Regards
Harish

Hi @Harish KM ,

 

I add the infor part

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("select_print_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'
});
 
and i can see sysid in logs but value is not getting populate and i also see error and warning in logs
suuriya_0-1698226173186.png

 

Hi @suuriya your table name is wrong here check bold line below

 

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("select_print_groups");

replace to

var almAssetGr = new GlideRecord("u_kallik_sites_codes_and_access_groups"); // put correct table name

HarishKM_0-1698226538421.png

 

// 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'
});

Regards
Harish