How can I hide a field if selection on dependant field has no choices

E_19
Giga Expert

Hi All,

I have 3 fields and they are choice field with dependency

Some choice in the 2nd field don't have any depended values in the 3 field.

I want to hide the 3 field if there are no depended choices.

Its a bit similar to OOB category/subcateogry except they don't hide the field if there are no sub categories.

Any suggestions welcome

Thanks,

Ellie

1 ACCEPTED SOLUTION

You can use the following script:-


  1. var gp = new GlideRecord('sys_choice');  
  2. gp.addQuery('dependent_value', newValue);  
  3. gp.addQuery('element', 'subcategory');   //If you have a label for it
  4. gp.query();  
  5. if(!gp.next())
  6. {  
  7.   g_form.setVisible('your variable', false);
  8. }

It might NOT be exactly the same, you might need to tweak it a bit but this is the general idea.


View solution in original post

6 REPLIES 6

Subhajit1
Giga Guru

Hi Ellie,


You will have to run onChange Client Script when you are changing the Cat 2 level field, query if that has any Cat 3 values, if results returned, do nothing, if results not returned, hide the field on the form.


Hi Das,



Do you mean GlideAjax? can you offer any help with this script


The field to hide if it IT Service choice has no IT Service component is it_component.



Many Thanks,


Ellie


You can use the following script:-


  1. var gp = new GlideRecord('sys_choice');  
  2. gp.addQuery('dependent_value', newValue);  
  3. gp.addQuery('element', 'subcategory');   //If you have a label for it
  4. gp.query();  
  5. if(!gp.next())
  6. {  
  7.   g_form.setVisible('your variable', false);
  8. }

It might NOT be exactly the same, you might need to tweak it a bit but this is the general idea.


Hi Das,



This is very helpful and I can tweak the script but can't quite get it to work



With the tweaked script below it always hides the it_service_component field even if it has a value or more.



var gp = new GlideRecord('sys_choice');


gp.addQuery('dependent_value', newValue);


gp.addQuery('element', 'u_it_service');   //If you have a label for it


gp.query();


if(!gp.next())


{


  g_form.setVisible('u_it_service_component', false);


}



Any idea?



Many Thanks,


Ellie