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

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.

Thank you!

I also prefer the UI Policy approach.

This worked like a charm 🙂

Rachel

Actually using the policy method, when I select the other OS's, the option is also hidden.  

I'm getting the same result with the Client Script Option:

I've attached a couple of screen shots of what I am seeing.

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