how to configure the dependent dropdown choices ?

skumar_srbh
Tera Guru

Hi .. .

I have a case where 2 dropdown list is available on form with same choices (ex. -  English, Hindi, Tamil, Telugu). I need to configure these options in a way that if user has selected "Tamil" in first dropdown then only rest 3 should be available in 2nd dropdown. Basically, selected choice in 1st dropdown should not be available in 2nd dropdown for selection and this should be working on both levels/view i.e. form and list.

could anyone help on this... 

Thanks,                                                                                                                                                                           Kumar   

 

6 REPLIES 6

Anil Lande
Kilo Patron

Hi,

You can use dependent field option or use below scripted way.

You need to write one onChange client script remove the option from 2nd field onChange of 1st field.

Your client script logic would be:

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

  if(newValue !=''){
	g_form.removeOption('secondField',newValue);

}else{  // When user clear 1st field
g_form.clearOptions('firstFieldName');
g_form.addOption('firstFieldName','english','English');  // use label and values as per your configuration
g_form.addOption('firstFieldName','hindi','Hindi');  /// use label and values as per your configuration
// simillarly add all other choices
}
}

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Boyan1
Kilo Sage

Good to know, then you can utilize the following approach - add client scripts onChange for both fields.

In them, you reset the value by using addOption or removeOption:

https://developer.servicenow.com/dev.do#!/reference/api/rome/client/c_GlideFormAPI#r_GlideformAddOption_String_String_String 

Best regards,

Boyan