Client script to remove option from select box based on another select box selection.

galavodasal
Giga Expert

We have a request to remove an option from select box B if a user selects a specific option in select box A.

Here's the client script I created, but it doesn't seem to be working. For testing, I tried changing onChange to onCellEdit and onLoad but nothing worked.

the g_form.removeOption is working. The option is removed if I comment out the if statement and force the removeOption through.

function onChange(control, oldValue, newValue, isLoading) {

var phoneUser = g_form.getValue = ('phone_user_type');

if (phoneUser == 'CCE Phone User') {

return g_form.removeOption('desk_phone', 'reconfigure');

    }

}

Thanks in advance

1 ACCEPTED SOLUTION

Oops, you need use label too. Use this. Please mark this one as correct, so that others who have same issue can find the right one



function onChange(control, oldValue, newValue, isLoading, isTemplate) {  


  if (isLoading || newValue === '') {  


  return;  


  }  


  var phoneUser = g_form.getValue('phone_user_type');  


  if (phoneUser == 'cce_phone_user') {  


  g_form.removeOption('desk_phone', 'reconfigure');  


  }  


  else{  


  if(!g_form.getOption('desk_phone','reconfigure')){  


  g_form.addOption('desk_phone','reconfigure','Put the label for the choice here');  


  }  


  }  


}  


View solution in original post

14 REPLIES 14

Here you go. Please mark this one as correct, so that others who have same issue can find the right one



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue === '') {


  return;


  }


  var phoneUser = g_form.getValue('phone_user_type');


  if (phoneUser == 'cce_phone_user') {


  g_form.removeOption('desk_phone', 'reconfigure');


  }


  else{


  if(!g_form.getOption('desk_phone','reconfigure')){


  g_form.addOption('desk_phone','reconfigure');


  }


  }


}


Awesome, you're super helpful. It added the option back, but the display is blank.



find_real_file.png



However, if I go ahead and process the request, the RITM form displays the value:



find_real_file.png


Oops, you need use label too. Use this. Please mark this one as correct, so that others who have same issue can find the right one



function onChange(control, oldValue, newValue, isLoading, isTemplate) {  


  if (isLoading || newValue === '') {  


  return;  


  }  


  var phoneUser = g_form.getValue('phone_user_type');  


  if (phoneUser == 'cce_phone_user') {  


  g_form.removeOption('desk_phone', 'reconfigure');  


  }  


  else{  


  if(!g_form.getOption('desk_phone','reconfigure')){  


  g_form.addOption('desk_phone','reconfigure','Put the label for the choice here');  


  }  


  }  


}  


Works perfectly, thank you so much Abhinay, this has been very helpful and informative.  



I hope you have a great day.


Glad I could help. You too have a great one