How to make choices in "choice list variable" visible based on the value of another variable field' in the same catalog item?

feroz4051
Mega Expert

How to make choices in "choice list variable" visible based on the value of another variable field' in the same catalog item?

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

HI Feroz,



you can use onchange client script wherein you can see the value selevted in field A and depending on that you can add/remove options in field B(choice List Variable)



Use these functions for the same



g_form.addOption('<Variable Name>','<value>','<display value>');   // To add options to the dropdown


g_form.clearOptions('<variable name>');   //To remove all values from the dropdown


g_form.removeOption('<Variable Name>', '<value>');   // To Remove 1 option from the dropdown


g_form.setValue('<Variable Name>','<value>');   // To select by default any one of the options.




Hope this helps.


-Anurag

View solution in original post

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Anurag Tripathi
Mega Patron
Mega Patron

HI Feroz,



you can use onchange client script wherein you can see the value selevted in field A and depending on that you can add/remove options in field B(choice List Variable)



Use these functions for the same



g_form.addOption('<Variable Name>','<value>','<display value>');   // To add options to the dropdown


g_form.clearOptions('<variable name>');   //To remove all values from the dropdown


g_form.removeOption('<Variable Name>', '<value>');   // To Remove 1 option from the dropdown


g_form.setValue('<Variable Name>','<value>');   // To select by default any one of the options.




Hope this helps.


-Anurag

Hi Anurag, Thanks for your reply. I have used below script I am facing two issues


1. script is hiding subcategory field for category choice = phone.


2. subcategory is visible to all other category choices but without subcategory options mouse & Pendrive.



My requirement is when category field   = phone then in subcategory mouse & pendrive should not be visible. And it should be visible to all other choices of category.



Catalog Client Script,


Onchange


Variable : Category



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


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


          return;


    }


var cat = g_form.getValue('category');


      if(cat == 'phone'){


g_form.removeOption('sb_ctgry', 'mouse');


g_form.removeOption('sb_ctgry', 'pendrive');


      }


}


Hi Feroz,



Try this code



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


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


          return;


    }


var cat = g_form.getValue('category');


      if(cat == 'phone'){


g_form.removeOption('sb_ctgry', 'mouse');


g_form.removeOption('sb_ctgry', 'pendrive');


      }


else


{


g_form.addOption('sb_ctgry', 'pendrive', 'pendrive');


g_form.addOption('sb_ctgry', 'mouse', 'mouse');


}


}


-Anurag