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

Atheher Fathima
Mega Guru

Hi Team,

 

My requirement is that i have three select box variables Department, team and roles. depending on the selection in variable department, the options in team and role should be shown or hidden. Example if user select department as finance then the Select box team should only show the options "HR" and role as "admin"

If user selects department as technology then we need to hide the HR from teams and admin from roles and display Operations.

 

Please advise how to achieve this via client script

1 ACCEPTED SOLUTION

Hi @Atheher Fathima 

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

var dep = g_form.getValue('department');
var role = g_form.getValue('role');
if (dep == 'Agency') {  //when comparing we have to use == operator
g_form.removeOption('team', 'Engineering and Architecture'); //replace with choice value if its label
} else {
g_form.addOption('team', '1', ' Agency'); //keep both the value and label in string format only
}
}

Thanks,
Murthy

View solution in original post

3 REPLIES 3

Murthy Ch
Giga Sage

Hi @Atheher Fathima 

You can use addOption and removeOption glide form methods here to achieve this.
Did you tried anything using onChange client script on department field/variable?

 

Thanks,
Murthy

Hi @Murthy Ch ,

 

I tried the below catalog client script

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

var dep = g_form.getValue('department');
var role = g_form.getValue('role');
if (dep = ' Agency') {
g_form.removeOption('team', 'Engineering and Architecture');
} else {
g_form.addOption('team', 1, ' Agency');
}
}

 

but it doesnt seem to work

Hi @Atheher Fathima 

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

var dep = g_form.getValue('department');
var role = g_form.getValue('role');
if (dep == 'Agency') {  //when comparing we have to use == operator
g_form.removeOption('team', 'Engineering and Architecture'); //replace with choice value if its label
} else {
g_form.addOption('team', '1', ' Agency'); //keep both the value and label in string format only
}
}

Thanks,
Murthy