Hiding Select Box Choices based on Select Box Variable Selection

Walter Toney
Tera Expert

Good Morning,

 

Current Instance is Tokyo - 

 

I have 2 Variables   on a Service Catalog

 

Variable 1 is a Selectbox  (Region) with Region I and Region II for Choices 

 

Variable 2 is a Selectbox (Territories) with DC, MD, NC,SC, PA

 

so my question is .. is there away to hide DC and MD in (Territories) if (Region) is Region I and Hide NC, SC, and PA if Region 2 is selected.  

 

This is what i attempted but it's not doing what is required

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    var reg = g_form.getValue('region');
    if (reg== 'Region I') {
        g_form.removeOption('territories', 'DC');
        g_form.removeOption('territories', 'MD');
    }
  if (reg == 'Region II') {
        g_form.removeOption('territories', 'NC');
        g_form.removeOption('territories', 'SC');
        g_form.removeOption('territories', 'PA');
}
1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage
Giga Sage

Hello @Walter Toney 

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    var reg = g_form.getValue('region');
    if (reg == 'Region I') {
        g_form.clearOptions('region');
        g_form.removeOption('territories', 'DC');
        g_form.removeOption('territories', 'MD');
    }
  if (reg == 'Region II') {
        g_form.clearOptions('region');
        g_form.removeOption('territories', 'NC');
        g_form.removeOption('territories', 'SC');
        g_form.removeOption('territories', 'PA');
}

 

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

View solution in original post

2 REPLIES 2

Samaksh Wani
Giga Sage
Giga Sage

Hello @Walter Toney 

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    var reg = g_form.getValue('region');
    if (reg == 'Region I') {
        g_form.clearOptions('region');
        g_form.removeOption('territories', 'DC');
        g_form.removeOption('territories', 'MD');
    }
  if (reg == 'Region II') {
        g_form.clearOptions('region');
        g_form.removeOption('territories', 'NC');
        g_form.removeOption('territories', 'SC');
        g_form.removeOption('territories', 'PA');
}

 

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

Rohit01998
Tera Guru

Hello @Walter Toney ,

 

Select 'Variable Name' field value = 'region' in catalog client script

And try this script...

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if ( newValue == "Region I" ){
g_form.removeOption('territories', 'DC');
g_form.removeOption('territories', 'MD');
g_form.addOption('territories', 'NC', 'NC');
g_form.addOption('territories', 'SC', 'SC');
g_form.addOption('territories', 'PA', 'PA');
}
else if ( newValue == "Region II" ){
g_form.removeOption('territories', 'NC');
g_form.removeOption('territories', 'SC');
g_form.removeOption('territories', 'PA');
g_form.addOption('territories', 'DC', 'DC');
g_form.addOption('territories', 'MD', 'MD');
}
}



Help others to find a correct solution by marking the appropriate response as correct answer and helpful.