Hiding Choices from one select box if a value is selected in another select box on Service Catalog

Tyler Johnson
Tera Expert

I have been trying to hide specific values on a select box if Cloud is selected. I searched the community and found several posts regarding this however when i try to replicate i fail. Can you please help me determine where I'm messing up? 

 

The value for field 1 is 'type_of_environment' 

The value for field 2 is 'database_type'

 

if The value 'Cloud' is selected for field 1 then it should remove the choices in field 2 with the value of 'EMR' and 'SnowFlake'

 

ive also tried a UI policy as well with no luck. 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var reg = g_form.getValue('type_of_environment');
    if (reg == 'Cloud') {
        g_form.clearOptions('type_of_environment');
        g_form.removeOption('database_type', 'SnowFlake');
        g_form.removeOption('database_type', 'EMR');
    }
   
}
1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @Tyler Johnson 

If you're using catalog item on the portal, let try to change the UI Type like below.

Timi_0-1708487077216.png

 

And your script could be like

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

    if (newValue == 'Cloud') {
        //g_form.clearOptions('type_of_environment'); //not sure about this line.
        g_form.removeOption('database_type', 'SnowFlake');
        g_form.removeOption('database_type', 'EMR');
    }else{
		//params: variable name, choice value, choice label
		g_form.addOption('database_type', 'SnowFlake', 'SnowFlake'); 
		g_form.addOption('database_type', 'EMR', 'EMR');
	}
   
}

 

 

Cheers,

Tai Vu

View solution in original post

1 REPLY 1

Tai Vu
Kilo Patron
Kilo Patron

Hi @Tyler Johnson 

If you're using catalog item on the portal, let try to change the UI Type like below.

Timi_0-1708487077216.png

 

And your script could be like

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

    if (newValue == 'Cloud') {
        //g_form.clearOptions('type_of_environment'); //not sure about this line.
        g_form.removeOption('database_type', 'SnowFlake');
        g_form.removeOption('database_type', 'EMR');
    }else{
		//params: variable name, choice value, choice label
		g_form.addOption('database_type', 'SnowFlake', 'SnowFlake'); 
		g_form.addOption('database_type', 'EMR', 'EMR');
	}
   
}

 

 

Cheers,

Tai Vu