Hide options from Select box variable depending on the option selected from previous select box

Krishna Priya
Tera Contributor
Hide options from Select box variable depending on the option selected from previous select box
 

My requirement is that i have two select box variables Platform name and work request depending on the selection in variable Platform name, the options in work request should be shown or hidden.

 

Please advise how to achieve this via client script

 

Below script implemented but if i change selection multiple times its not working. Please advice where the issue.

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

    var platform = g_form.getValue('Platform_name');
    var work_request = g_form.setValue('work_request');

    if (platform == "Email") {
        g_form.removeOption('work_request', "domain");
        g_form.addOption('work_request', "Data ");
        g_form.addOption('work_request', "Email");

    } else if (platform == "Endpoint") {
        g_form.removeOption('work_request', "Email");
        g_form.addOption('work_request', "Data");
        g_form.addOption('work_request', "domain");
    }
}
9 REPLIES 9

Hi,

I also had the same requirement but a small change if i select a variable then another variableset to be hidden. can anyone help me please

Hi @KM10 

I understand you have a similar requirement, and I'd be happy to assist you. I will provide you a reply on your thread.

Thank You!!

@Aniket Chavan its not working. Do we need to mention clear function ? Please help me with script.

 

Alp Utku
Mega Sage

for g_form.addOption() function, you need to indicate both display value and actual value. Something like below.

 

g_form.addOption('field_name_of_dropdown', 'display_name_of_dropdown_option', 'actual_value_of_dropdown_option') ;

Aniket Chavan
Tera Sage
Tera Sage

Hello @Krishna Priya ,

Kindly test the updated script provided below. Ensure that you verify the backend names of your variables and replace them accordingly. I've successfully tested this functionality with two select box variables on my end, and it performed as expected. Let me know how it works for you.

 

 

function onChange(control, oldValue, newValue, isLoading) {
    // Check if the form is still loading or if the new value is empty
    if (isLoading || newValue === '') {
        return;
    }

    // Get the value of the 'platform_name' field
    var platform = g_form.getValue('Platform_name');

    // Define the field for 'work_request'
    var workRequestField = 'work_request';

    // Add options based on the selected platform
    if (platform === 'Email') {
        g_form.removeOption(workRequestField, 'domain');
        g_form.addOption(workRequestField, 'Data', 'Data');
        g_form.addOption(workRequestField, 'Email', 'Email');
    } else if (platform === 'Endpoint') {
        g_form.removeOption(workRequestField, 'Email');
        g_form.addOption(workRequestField, 'Data', 'Data');
        g_form.addOption(workRequestField, 'domain', 'domain');
    }
}


Additionally, I recommend exploring the following links, which provide detailed insights into the syntax and usage, making it easier for you to understand and implement:

 

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket