Hide a variable option

rachelconstanti
Mega Sage

I have a hardware catalog item.

We have 'Operating System' has a Select Box Variable.

We have 'System Type' has a Select Box Variable.

 

If RHEL is selected for the Operating System, I need to hide one of the values in System Type.

 

How can I accomplish this?

 

Thank you in advance,

Rachel

3 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@rachelconstanti You can choose to create a UI Policy on your catalog item using which you can implement this requirement easily. 

In your, UI Policy put a condition Operating System is RHEL using the condition builder.

Check the the script checkbox on your UI Policy

In script tab add following if the condition evaluates to true

function onCondition(){
g_form.removeOption('system_type','<name of the option which needs to be hidden>');
}

use the following script if the condition evaluates to false.

function onCondition(){

g_form.addOption('system_type','<name of the option which needs to be hidden>');

}

 

Another alternative is to implement this via an OnChange Client script on Operating System variable. 

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

    //Type appropriate comment here, and begin script below
    if (newValue == 'RHEL') {
        g_form.removeOption('system_type', 'name of option to be removed');
    }
else{
        g_form.addOption('system_type', 'name of option to be added'); //add the option here if the OS is not RHEL
}
}

Between these two approaches I prefer UI Policy approach more.

View solution in original post

@rachelconstanti Can you share the screenshot of your UI Policy please. 

View solution in original post

@rachelconstanti Could you please update Execute if false script to as follows.

 

function  onCondition(){
g_form.addOption('system_type','draper_personal','Core Business Use (Draper Personal)');
}

Hope this helps.

View solution in original post

11 REPLIES 11

Here are the screen shots:

 

If RHEL is selected, Core Business Use (draper_personal) should not display.

Tai Vu
Kilo Patron
Kilo Patron

Hi @rachelconstanti 

We can manage the options through the API below.

addOption

 

So, just create your OnChange Client Script on the Operating System variable. Then check the value is RHEL, we refresh the options of System Type accordingly.

Sample below.

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

    //None
    if (newValue === '') {
        g_form.clearOptions('system_type');
        g_form.clearValue('system_type');
        g_form.addOption('system_type', '', '-- None --');
		//add all the remaining options.
        return;
    }

    if (newValue === 'RHEL') {
        g_form.clearOptions('system_type');
        g_form.addOption('system_type', '', '-- None --');
		//add the options available for operating system RHEL.
        return;
    }
}

 

Let me know if it works for you.

 

Cheers,

Tai Vu