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

Krishna Priya
Tera Contributor
ide 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.

 

do i need to add clear value ? If so please correct my code and help me out on this.

 
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");
    }
}
2 REPLIES 2

BalaG
Kilo Sage

Hello @Krishna Priya ,  yes you use clearOptions method to reset the choice list. In addition you should be using newValue in your conditional code, and  also add default branch to add all options back. Assuming you have just three values in your choice list, the following code should work  (Note the field names are different on my PDI)

 

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

   //Type appropriate comment here, and begin script below
	g_form.clearOptions('u_work_request');

    if (newValue === 'Email') {
        g_form.addOption('u_work_request', 0, "data");
        g_form.addOption('u_work_request', 1, "email");

    } else if (newValue === 'Endpoint') {
        g_form.addOption('u_work_request', 0, "data");
        g_form.addOption('u_work_request', 2, "domain");
		
    } else {
		g_form.addOption('u_work_request', 0, "data");
		g_form.addOption('u_work_request', 1, "email");
        g_form.addOption('u_work_request', 2, "domain");
     }
}

 

Hope this helps

--

Bala Guthy

 

If this answer solved your issue or just helped, please mark this as a solution or as helpful.

 

Brad Bowman
Kilo Patron
Kilo Patron

Because the selection can be changed multiple times, it's best to clear the choices with each change, then re-build the list with the ones you want for each case, so it would look more like this - also removing the setValue line as it is not constructed correctly or doing anything:

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

    var platform = g_form.getValue('Platform_name');
    if (platform == "Email") {
        g_form.clearOptions('work_request');
        g_form.addOption('work_request', "Data ");
        g_form.addOption('work_request', "Email");
     } else if (platform == "Endpoint") {
        g_form.clearOptions('work_request');
        g_form.addOption('work_request', "Data");
        g_form.addOption('work_request', "domain");
    }
}