Hide/Visible choices based on selection of another field?

Viraj Sapte
Tera Expert

Hi,

I have created two variables of "Multiple Choice" data type in a CI: Type and Schedule and I have the following requirement - 
If Type = "DEV" or "TEST", then, display choices as "T6", "T8", "T10".
If Type = "PROD", then, display choices as "S6", "S8", "S10".
What is the best way to fulfil this requirement?
find_real_file.png

find_real_file.png

Thank you in advance.

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

Please use the below script in Onchange Catalog client script:-

Script:-

var type=g_form.getValue('type');

if(type=='dev'||type=='test')

{

g_form.removeOption('schedule','s6');

g_form.removeOption('schedule','s8');

g_form.removeOption('schedule','s10');

}

else

if(type=='prod')

{

g_form.removeOption('schedule','t6');

g_form.removeOption('schedule','t8');

g_form.removeOption('schedule','t10');

}

 

Please mark answer correct/helpful based on Impact

 

 

View solution in original post

5 REPLIES 5

Voona Rohila
Kilo Patron
Kilo Patron

Hi Viraj 

In your Onchange Catalog client script of type field

Try this approach so that if user goes back and forth with type variable choices then there wont be missing values.

var type=g_form.getValue('type');

g_form.clearOptions('schedule');

g_form.addOption('dropdown1','','-- None --',100);

if(type=='dev'||type=='test') //you can also use newValue instead of type.

{
//remove that are not required.

g_form.removeOption('schedule','s6');

g_form.removeOption('schedule','s8');

g_form.removeOption('schedule','s10');

//add all options thar are required

g_form.addOption('schedule','t6','T6');

g_form.addOption('schedule','t8','T8');

g_form.addOption('schedule','t10','T10');

}

else if(type=='prod')

{

g_form.removeOption('schedule','t6');

g_form.removeOption('schedule','t8');

g_form.removeOption('schedule','t10');

g_form.addOption('schedule','s6','S6');

g_form.addOption('schedule','s8','S8');

g_form.addOption('schedule','s10','S10');

}

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP