When a Town is selected, automatically populate the corresponding District and Region

Hello,

I want to be able to configure my form such that when a Town is selected from a dropdown, the town's corresponding District and Region are automatically populated.

If I were to use Cascading Select, I could first select the Region, then select from the Districts in that Region, then select from the Towns in that District. However this does not work for my use case. Aside from there being three selects to make instead of one, my enumerators are recording the details of Google Plus Code address signs affixed to properties that includes the Town name. I want to make it such that once they select the town name, the remaining fields auto-populate.

Thanks in advance for your help!

Create a CSV file containing the list of towns mapped with the district and region. First provide a select_one question and allow user to select a town first, then use two Calculate variable to fetch District as well as the region for the selected town from external dataset using pulldata() function.

Ok thank you very much, I will look into the pulldata function!

I agree with @joybindroo's approach, but note that this requires you to have unique town names. If you have multiple towns with the same name, you'll need to adjust the town value and label to something unique (e.g., Paris-France, Paris-Indiana, Paris-Indonesia).

Don't use pulldata() because it's not standards-compliant. Instead, use instance() as described at https://docs.getodk.org/form-datasets/#referencing-values-in-datasets. You can also find a cheatsheet for instance() expressions in the XLSForm template at https://docs.getodk.org/xlsform/.

I'd only use pulldata() or search() if you are experiencing performance problems. These problems typically happen if you have more than 50K rows.

5 Likes

I have a follow up question if I may... I need the form to be able to work offline in the field. Is this possible with the instance() function (or pulldata for that matter)?

Thanks!

Yes, the instance() function works entirely offline.