Cannot create a dynamic choice list in a form for a dependent reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2012 03:49 AM
I have 2 reference fields in a form.
The allowed value in the second field is restricted by the current value of the first field.
The possible values for the second field are determined by a javascript function (in a business rule) called by the Reference qualifier for the second field.
On changing the value in the first field the choices available for the second field change.
This is the behavior that is required.
When I open the Reference Lookup for the second field the values displayed are correct and are related to the value in the first field.
If I change the value in the first field the values displayed in the Reference Lookup for the second field change accordingly.
I would like to do the exact same thing but with the second field being a choice list.
I have tried to do this by defining the second field as a choice list by modifying its dictionary entry.
But the available options that appear are not being restricted by the value in the first field.
Also, changing the value in the first field does not cause a change in the option list of the second field.
I also tried implementing the same behaviour using a client script triggered by the onchange event in the first field. I can remove options from the choice list but I can not find a way for the glide_form addOption() function to work.
I got no javascript errors in the browser, just no options added to the choice list.
Is it possible to create a dependent field which is a choice list with the behavior that I want? ie. a dynamic choice list whose options are determined by the value chosen for another field.
thanks in advance
mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2012 01:08 PM
Mike,
Great question. I have been working through it as I was a bit curious about it too. I replicated the issue and blogged my troubleshooting: http://dales-tech-notes.blogspot.com/2012/04/choice-lists-and-servicenow.html
Unfortunately, I don't have an answer. It appears in the wiki (http://wiki.service-now.com/index.php?title=Reference_Qualifiers#Advanced_Reference_Qualifiers) that you should be able to do this by adding the attribute "ref_qual_elements" and then creating a business rule to return the qualification that will constrain the choice list. However, I admit that I am pretty new with ServiceNow and I cannot get it to work. (I think my problem is getting the business rule to fire.)
Have you tried that attribute and method indicated in the article?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2013 09:07 AM
I think that for this matter, a client script would be more appropriated... what do you think?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2012 01:54 PM
This is possible and it works the same way as standard dependent fields (category and subcategory for example). The first step is to personalize the dictionary for the choice field and set the 'Dependent' field value to the database name of your reference field. Then you just set the value in the reference field that you want to define choices for. Once you've done that, just right-click your choice field and add choices. This will store a 'dependent' value on all of the choices (the sys_id of your reference field).
http://wiki.service-now.com/index.php?title=Creating_New_Fields#Making_a_Field_Dependent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2012 03:58 PM
If I understand you correctly, you are referring to a solution where the second field is a Choice field, not a Reference field with Choice List as way in which the field is displayed. See the graphic in my blog post for more information ... assuming I got correct what Mike meant in the first place! :^)
If you set the "Choice", "Choice Table", and "Choice Field" values of the second Reference field the resulting selection list is fully populated, but not constrained. These are not supposed to be static values, but dynamic based upon the first field's value.
In pseudo-code the query menu would have a query something like:
select u_subcategory_field from u_subcategory_table where u_category_field = current.u_category_field
There either needs to be code attached to the first field - so it rebuilds the list's values when the first field's value changes - or there needs to be code on the second field - so it rebuilds the list's values when the second field is clicked. I was expecting the attribute indicated in the SN wiki to insert some code for that purpose. Given the description, it seems logical. You would have the client make an AJAX call to a server-side function (business rule), passing the current value of the first field so it could return an array with which to rebuild the selection list. I did not see any such code change when I followed the instructions in the wiki. (Although I admit that I did not diff the two frame sources - maybe something for tonight's exploration.)
The reason I am tracking this is because dependent menus is a very common design pattern and it is not obvious how it works in ServiceNow. Again, I have not been doing ServiceNow that long; you talk about "standard dependent fields (category and subcategory for example)". Can you elaborate where an example of two Reference fields displaying as selection lists - with the second field's value constrained by the first - is in the basic implementation?
Great topic and thanks for your response.