Popular Help Content
Our sample creates two tables (state and district). The district table has three fields (id, name and state_id). The state_id will be used to filter the list of districts based on the selected state. The following image shows our final setup.
Create a Select List Based on a Lookup Table
To create a select list based on a lookup table, first add a single select question to your form.
If you were to test this application, you'd see the first question displays a list of all states and the second question displays a list of all districts (irrespective of the selected state). To filter the district list, we need to add a filter condition to the itemset.
Filtering the ItemSet
To filter an item set, you can use the 'Filter Option' under 'Lookup Table Data' (similar to the expressions used when defining Display Logic or Calculations in your form). In our example, we'll filter the District item list based on the selected state. Our district table contains a field called "state_id". The values in this match the value specified for the state question.
The left option will show an autocomplete widget to help you pick a lookup table attribute and the right option will allow you to drag a question from the question tree.
Testing an application with lookup tables
In order to test the conditional select options and other logic works in the application, you must sign on as a mobile user and submit 'real' data to the server. If you see an error when opening the form that states "Could not find an appropriate fixture for src: jr://fixture/item-list:table_name" you have not properly setup your lookup tables.
Large lookup tables may cause an error on the mobile device stating "get field slot from row 0 col 1 failed." This is due to the amount of memory allocated to the lookup table on the mobile device. The lookup table is larger than the available memory. If you get this error, a common work around is to split the table into multiple tables. This can be completed by adding a "more" option to the bottom of your first lookup table and performing a conditional question to display the results of the second lookup table if "more" is selected. For example, there are more than 3,600 Village Development Committees (VDC) in Nepal across 75 districts. One user created a conditional select option to display the VDCs within the selected district. However, the VDC list was too large to display in one lookup table. The user created three lookup tables that each supported the VDCs of 25 districts. Three VDC questions were created with conditional criteria that displayed the VDCs from one of the three lookup tables. Finally, a calculated question was created to determine which VDC was selected from the three VDC questions.
Training an application with lookup tables
- Generic User: Create a generic user called "dimagi" or "demo" and update the table specifically for this user - populating all the conditional select options with the same 'dimagi' or 'demo'. As long as the partner is aware of the use case, they will be able to filter out this user in reports. During training, mobile users will sign onto CommCare and submit live 'practice' data. Work with the partner to specify a date where all data submitted to CommCare HQ is considered actual data for program purposes. This should be made clear to the FLWs and to the data analyst/M&E officer.
- Training Application: Copy the final application - remove the conditional select options from the application. This app can be used during training as a training application and the users can enter data in demo mode.
- No SIM: If the partner has not secured SIM cards for the phones prior to training, install CommCare on all the phones. Use one SIM card to restore the user or practice user ('dimagi' or 'demo') to all phones. The phone will update according to the latest lookup table on HQ. Remove the SIM. The conditional select options will work on the phones and the data will not be submitted to the CommCare HQ.