UI policy on list collectors

scottjus82
Kilo Guru

Hey all,

Is it possible to have a conditional field based on a list collector on a catalog item? I can't seem to get mine working, starting to wonder if its the way a list collector works

I need a multi line text field to show if the list collector includes "Additional hardware, not listed"

Any thoughts?

Justin

1 ACCEPTED SOLUTION

amlanpal
Kilo Sage

Hi Steve,



Please write an onChange Catalog Client Script for the item with the change of that List Collector type variable. The script should be as of below. I also have answered similar one, which you can refer: setMandatory if ListCollector contains specific value



function onChange(control, oldValue, newValue, isLoading) {


      if (newValue == '') {


              g_form.setMandatory('variable_name', false); //Put the multi line type variable name which is needed to be mandatory


              g_form.setDisplay('variable_name', false); //Put the same multi line type variable name which is needed to be visible at the same time


              return;


      }


   


      if (isLoading || newValue != ''){


              if (newValue.toString().indexOf("sys_id") >-1) {   //Pass the sys_id of record 'Additional hardware, not listed'. You can get the sys_id of the record from the referred table


              g_form.setMandatory('variable_name', true);


              g_form.setDisplay('variable_name', true);


              }


              else


                      {


              g_form.setMandatory('variable_name', false);


              g_form.setDisplay('variable_name', false);


              }


           


      }


}



I hope this helps.Please mark correct/helpful based on impact


View solution in original post

5 REPLIES 5

shloke04
Kilo Patron

Hi Steve,



Below link may be useful which has the same approach for your query:



Need help to show fields based on list collector values




Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hey Shloke,



Thanks for the response, I have taken the script and changed it to match my tables and fields however its still not working. My script is below. Any thoughts on why its not working?



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




  var values = g_form.getValue('select_hardware') //list collector field


var splitValues = values.split(',');


var g = new GlideRecord('u_pn_hardware'); // table my list collector references


g.addQuery('select_hardware','Additional Particular Needs Hardware (not listed)',splitValues);// list collector field and choice needed to show the additional field


g.query();


if(g.next()){


g_form.setDisplay('additional_hardware_details',true); // field that needs to be shown if above choice is selected


g_form.setMandatory('additional_hardware_details',true);// as above, making field mandatory


}    


}


amlanpal
Kilo Sage

Hi Steve,



Please write an onChange Catalog Client Script for the item with the change of that List Collector type variable. The script should be as of below. I also have answered similar one, which you can refer: setMandatory if ListCollector contains specific value



function onChange(control, oldValue, newValue, isLoading) {


      if (newValue == '') {


              g_form.setMandatory('variable_name', false); //Put the multi line type variable name which is needed to be mandatory


              g_form.setDisplay('variable_name', false); //Put the same multi line type variable name which is needed to be visible at the same time


              return;


      }


   


      if (isLoading || newValue != ''){


              if (newValue.toString().indexOf("sys_id") >-1) {   //Pass the sys_id of record 'Additional hardware, not listed'. You can get the sys_id of the record from the referred table


              g_form.setMandatory('variable_name', true);


              g_form.setDisplay('variable_name', true);


              }


              else


                      {


              g_form.setMandatory('variable_name', false);


              g_form.setDisplay('variable_name', false);


              }


           


      }


}



I hope this helps.Please mark correct/helpful based on impact


Legend. That works perfectly. Thank you very much. Most appreciated.