Use lookup table for data validation/display condition?


Would it be possible to use lookup table for validation or display conditions? I have a question that asks for a zip code and would like to check against a lookup table to determine if that value is in the table and thus trigger a series of questions. If possible - how would one implement this?


Yes, you should be able to do that.

Edit the form XML and add an “instance” line that references the name of the table. You can place this above any existing instance tags in your form.

<instance id="zipcodes" src="jr://fixture/item-list:zipcodes"></instance>

You can then reference the lookup table in xpath expressions as instance('zipcodes'). Your display condition would then probably look something like this:

selected(instance('zipcodes')/zipcodes/zipcodes_list/zipcodes/zipcode, /data/selected_zip_code

Working with lookup tables and itemsets is pretty tricky, so I’d make judicious use of the Evaluate XPath utility in trying to make this work.