For users already familiar with CommCare's conditional select functionality, referencing locations within a form is very similar. To access the list of locations from within a CommCare Supply form, you can use the syntax described HERE.
Much like lookup tables in order to reference location data in a form, you must first include a reference to this instance in the forms xml. To access this xml, enter your form, and in the top righthand corner, under "Tools", select "Edit Source XML"
...
- Add a Single/Multiple Answer Lookup Table:
- Click on the "Lookup Table Data" question
- Edit the following fields:
- Lookup Table: ignore that for now: click on the 3 dots next to the field and complete the following fields.
- Query expression: put here your location instance. For example:
- if you want to display the list of states: instance('locations')/states/state
- if you want to display the list of districts of a previously selected state: instance('locations')/states/state[site_code=/data/state_selected]/districts/district
where /data/state_selected is the state previously selected.
- Instance ID: locations
- Instance URI: jr://fixture/commtrack:locations
- Query expression: put here your location instance. For example:
- Value Field: what you want to save as an answer (usually an id or a code). For locations you can use site_code or @id.
- Label Field: what you want to display to the user. For locations you can use name
- (Optional) Filter: can be used to filter the locations displayed.
- Lookup Table: ignore that for now: click on the 3 dots next to the field and complete the following fields.
- Click on Tools / Edit Source XML on the top right corner of the form builder:
- Then in the expression <itemset nodeset="instance('products')/products/product">, replace the instance with the instance of your location. For example
- if you want to display the list of states: instance('locations')/states/state
- if you want to select the list of
In this example my lookup question is /data/location_loookup
If you don't see the 3 dots (), you need to activate a feature flag in your project settings.
Add the feature preview "Custom Single and Multiple Answer Questions" to your project