One field is dependent on two fields

alvatindra
Giga Contributor

Hi,

I have category and subcategory choice fields on change form.

subcategory field values depends on both type and category choice fields.

Ex:

If category is x and type is normal then subcategory should be p,q

if category is x and type is emergency then subcategory should be y,z

how to achieve two way dependency on subcategory field?

11 REPLIES 11

Hi Deep K,



I have never worked on this,I will try and get back to you.



Thank You


They are not too difficult. Again, see the incident lookup as an example.


Hi Chuck,


lookup rules sets the value but they doesn't retrieve/populate the subcategory choices based on category and type here.


Is subcategory still dependent on category (in the dictionary definition)?



Go to the form, right click on the field label and select Configure Dictionary. Look at the Dependent field section and see if it is still set to category.



find_real_file.png


I know this is an old post, but if your still working on this I think I understand what you are trying to accomplish.



You want something like if fieldA=valueA AND fieldB=valueB THEN choices available *to choose from* in fieldC are [x, y, z].



I don't think this is supported by adding records in the sys_choice table like you normally would.   Instead you would need to script it out in a (i think you need to put it in a client script).



To do this you would use ServiceNow's GlideForm http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#gsc.tab=0



To do something like that it might look like:



if(g_form.getValue('fieldA') == 'valueA' ${AND} g_form.getValue('fieldB') == 'valueB'){


        g_form.addOption('fieldC','x','x',1);


        g_form.addOption('fieldC','y','y',2);


        g_form.addOption('fieldC','z','z',3);


}



Disclaimer: I haven't played with client scripts yet, so I might be wrong.   Also, you'll want to think about how to reverse this script if someone changes one of the values in fieldA or fieldB.   Likely by calling g_form.removeOption()