Hide/Show select box variable based on the another select box variable

ronro2
Tera Contributor

Hey guys! 

I want to create an onchange client script for a catalog item based on selection in select box 'order_type', which has three choices: 'new_environment', 'change' and 'decommissioning'.

When 'new_environment' is selected in 'order_type' then we should hide the selection 'no_change' in select box 'node_size' and 'no_change' in select box 'node_amount'.

If you change 'order_type' to 'change' or 'decommissioning' then 'no_change' should be restored and visible.

So when: 

ronro2_0-1742816960343.png

I want to hide: 

ronro2_1-1742817041080.pngronro2_2-1742817076823.png

 

I just can't get it to work. 

Thanks in advance!

1 ACCEPTED SOLUTION

Hello @ronro2 

 

It doesn't works like that with choice type variables. You need to clear the options first. 

Use this ➡️ g_form. clearOptions('<FIELD_NAME>'); 

 

Then if you want to add another option you need one by one add it. 

 

GlideForm - addOption(String fieldName, String choiceValue, String choiceLabel)

 

If only it is independent field not depending on any other field then it would work rhe way you are doing but otherwise if there is dependency. You need to follow above. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

Cc - @Dr Atul G- LNG 

View solution in original post

8 REPLIES 8

Hey @Ankur Bawiskar !

This is my script: 

 

function onChange(control, oldValue, newValue, isLoading) {
    // Return if the form is loading or no value is selected
    if (isLoading || newValue === '') {
        return;
    }

    // Check if the selected order type is 'change'
    if (newValue === 'change') {
        // Add 'no_change' as a default option to node_size
        g_form.addOption('node_size', 'no_change', 'Inga förändringar');
        
        // Add 'no_change' as a default option to node_amount
        g_form.addOption('node_amount', 'no_change', 'Inga förändringar');
        
        // Optionally set the default value to 'no_change'
        g_form.setValue('node_size', 'no_change');
        g_form.setValue('node_amount', 'no_change');
		
    } else {
        // Remove 'no_change' options when other order types are selected
        g_form.removeOption('node_size', 'no_change');
        g_form.removeOption('node_amount', 'no_change');
        
        // Clear the values
        g_form.setValue('node_size', '');
        g_form.setValue('node_amount', '');
    }
}


It is not working however. I've removed the 'no_change' from the variable and tried to add it via the script above. 

Hello @ronro2 

 

It doesn't works like that with choice type variables. You need to clear the options first. 

Use this ➡️ g_form. clearOptions('<FIELD_NAME>'); 

 

Then if you want to add another option you need one by one add it. 

 

GlideForm - addOption(String fieldName, String choiceValue, String choiceLabel)

 

If only it is independent field not depending on any other field then it would work rhe way you are doing but otherwise if there is dependency. You need to follow above. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

Cc - @Dr Atul G- LNG 

ronro2
Tera Contributor

@Shivalika & @Dr Atul G- LNG thank you guys! 

Hello @ronro2 

 

I am glad my reply answered your query !! 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY