ODK 2 - multiple field select

I’m trying to extract a pair of associated variables from a pair of selected variables to create an ID. All variables are in a csv file, which is referenced in the queries tab. The associated variables are just two sets of code numbers, the selected variables are the Health Centre names and the village names, with villages nested in Health Centers in a cascading select. I have used the ‘region’ and ‘country’ example in the ODK2 documentation to do this.

I can extract the names without issue, however I can’t work out how to set up the app’s Excel file to effectively replace these selected variables with the codes to create the ID without names.

Anyone have any helpful ideas?! I’m sure this will be the first of many posts as I struggle with moving from ODK 1 to 2!

Many thanks!

Dear @arthurriedel,

There may be a nice way to map back the codes rather than the names, but alas I do not know it! However, when we ran into a similar problem we actually just solved it in Excel by concatenating the name and code together to have half as many columns, which was particularly helpful given that our lists were very long.

For example, we had countries with code 400, text Jordan and concatenated 400_Jordan. This was then very easy to record and fieldworkers who knew either the code or text could use this; then in processing the data we split them apart at the “_”. Not sure if this work-around will work for your case or not.


IF I understand your question correctly, I think you can accomplish what you want by adding more columns to the csv for the name you want to use.

Let’s assume we have a csv with column headers region_code, country_code, name_of_country. I assume you only want to display the “name_of_country” and save the “country_code” in the database.

To do this I believe the example callback function on the queries doc page would become:

_.map(context, function(place){
place.data_value = place.country_code;
place.display = {title: {text:place.name_of_country} };
return place;

Thank you Caroline & Waylon for responding!

I am relieved that I described the issue well enough that you both understood the problem!

Unfortunately I don’t think I can use Caroline’s clever workaround here. Trying out the revised code of Waylon’s leads to some quirky behavior: the ID construction for the second part (village, in my case) returns ‘null’. However if I back out through the survey, the ID number for village is recorded correctly. I will also have to try to select a similar numeric code for the Health Centre, but ‘pluck’ is not allowing me to return more than one variable at the moment — perhaps I will have to use another term.

Many thanks again both,

A couple follow up thoughts: when you say the code is null but when you back out is recorded correctly, do you mean you have to navigate forward or backward for the data to record? I can’t remember off the top of my head the cases where this occurs, but we did find that in some cases ODK2 only “evaluates” certain calculations when you navigate on (think of it like hitting enter). This may be true in your case. I also think that one query usually maps to creating one variable at a time—but you should be able to use a very similar query to get the health center code.