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

Harish KM
Kilo Patron
Kilo Patron

Hi @suuriya ,

Create a client callable script include and client script like below

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("cmdb_ci"); // 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('name')); // pass the field name where you want to populate values on other field
               }
            return CI.join();
    },
 
Client script:
function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var getCI = g_form.getValue('business_application').split(","); // list collector variable name
  var ga = new GlideAjax("demoAjax"); // 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('test',answer); // set the values to the field
    }
   
   
}
 
Example:
HarishKM_0-1698200981550.png

 

Regards
Harish

HI @Harish KM ,

 

Thanks for the reply but this is not my requirement.

It populating the same values selected in list collector field to other field.....but mine is different on selecting the value in list field a set of name need to populate in multi select field.

 

Hi @suuriya I just shared the example. In my example it is showing same values because I took CI name to populate though i select CI name. You need to pass correct field values for your logic

Regards
Harish

Hi @Harish KM ,

 

I tried the script but it is not working.

Client script: onchange variable select print group

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: client callable enabled
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('printers_included_in_group')); // pass the field name where you want to populate values on other field
               }
            return CI.join();
    },
    type: 'Printer'
});
 

suuriya_0-1698219741593.pngsuuriya_1-1698219768236.png

FYI select site name is lookup select box with kallik table and select print groups is list collector with kallik table and select print group variable is dependent on select site name variable by this

suuriya_2-1698220183107.png

on selecting these value

suuriya_3-1698220315495.png

the printer value mentioned in kallik table need to populate in mutliple line field