1. What is the issue? Please be detailed.
I`m trying to use the instance function to filter an entity list in a select_one question. The entity dataset is called: viviendas. I have two forms. The first one is responsible for populating the viviendas entity list. Each register in the entity list comes from a select_one type of question, with one last field corresponding to the address(Street_name) where the survey will be performed. The address field is of type text.
The second form should access the entity list, showing only the address registers that met one of the options defined in the first form.
For example, I have an enumeration_area field and address fields in form number 1. Each enumeration_area has multiple addresses under it. The second form also has the field enumeration_area with the same options as the first form. What I would like is for the instance function to show me only the addresses registered in the Viviendas entity dataset under the enumeration_area selected in the second form that currently exists in the entity list.
2. What have you tried to fix the issue?
Seems to be simple but Im struggling with this. I went through all the documentation for entities, and I dont know if the expression: instance('viviendas')/root/item[enumeration_area=${enumeration_area}]/Street_name should be placed in the second form under the calculation field, or choice filter. I tried multiple approaches, testing in the calculation and in the choice filter columns, both resulting in a blank selection with no address to select.
If I remove the expression from the choice_filter with no expression in the calculation column, Im getting the full list of addresses unfiltered. This is a problem because I have thousands. Its complicated to navigate from 1000 registries looking for 1 specific address. X
3. Upload any forms or screenshots you can share publicly below.
Entity dataset
If each item in your entity list viviendas is a survey location / address that should be filtered and selectable by picking the label of the entity item, I think you only need a choice filter (not a calculation) to filter your entity list as: enumeration_area=${enumeration_area}
So for the selected value ${enumeration_area}, eg Area_Rivera_0001, only entity items that match would be available for selection, eg from your screen shot, entity items 152, 151, 148, 147, 144, 143, 142.
If your enumeration area question is using an entity list of areas, and is returning the UUID, this won't work as there's no match, and you'll either need a parameters expression like value=enumeration_area_name and add these values to it, or to add the enumeration area UUID as a field in your viviendas entity list. If it's a CSV/internal choice list and the name value matches the enumeration_area then no problem.
But - you mention street_name - is this the item you are trying to select from? Your form or an extract from it would help.
Hi Andrew, thanks for your help.
You perfectly described what I'm trying to get. Despite adding the expression to the choice filter I'm getting no address to select. If I remove the choice filter options, I get all the addresses from the Viviendas entity dataset. For some strange reason, the choice filter is not filtering the entities' registries and is returning me the address under each enumeration_area.
I would like to get for the Area_Rivera_0001 all the address registered under this category.
I'm not using an entity list of areas to return the UUID. Street name is the field from the de viviendas entity dataset that I would like to be returned as a result of the choice filter expression. The form is attached. The Viviendas_identification form is responsible for generating the entities; the other is the one where the choice filter option isn;t working. Viviendas_identificacion - Form 1.xlsx (253.8 KB) Data_collection_viviendas - Form 2 - Copia.xlsx (235.4 KB)
Have you tried replacing your choice filter: instance('viviendas')/root/item[enumeration_area=${enumeration_area}]/Street_name
with just this: enumeration_area=${enumeration_area}?
That will take the user selected value from "Enter the enumeration zone", and filter the entity list down to those that match in the entity list column "enumeration_area", so, again, from your screenshot, if Area_Rivera_0004 was selected, then only item #145 would be available to select at "Select the structure to fill the data.", with the Label shown as defined in your Viviendas_Identificacion form as concat(${departamento}, " - ",${municipio} , " - ", ${area_trabajo}, " - ",${street_name})
The label is truncated in the screenshot, but assume it would be "Rivera - Seccional Policial # 9 - Area Trabajo 1 - Ceballos 123"
That sounds like what you are trying to do (select enumeration area, return all entity list items with matching enumeration area to select one and collect structure data)
Side note: Is 'street_name' unique within parent fields? Is it possible to have two entries with the same values for ${departamento}, ${municipio} , ${area_trabajo}, ${street_name}? (where street_name is "Record the name of the street where you are collecting data, and the structure number"). If so, you will end up with two select options that have different UUID/name values in the entity list but the labels will be identical so you can't tell them apart.
Hi Andrew, thanks for you comment. You are very kind and an expert. Your last suggestion to replace the instance('viviendas')/root/item[enumeration_area=${enumeration_area}]/Street_name
with just this:
enumeration_area=${enumeration_area} fixed the problem.
I appreciate your help, but it is intriguing to me how the entity management documentation does not mention this possibility. I did exactly as they recommended, but I had no results. Thanks for your help.
Thanks so much for the amazing explanations, @ahblake!
@Thiago_Rocha can you please link to the docs section you were looking at where you might have expected more information about filtering lists? Let's improve that!
Sure, under the (https://docs.getodk.org/entities-intro/) there is a section regarding this (I need to assign specific Entities to specific data collectors, how can I represent this?) I think that a mention to this possibility to use choice filters not applying the entire lookup function structure following an Xpath expression can be helpful for the users.
For now, you can limit the Entities that are available from a select_one_from_file using a choice_filter.
The link isn't quite right, I've updated it here, this points to how you can apply a choice filter.
In the following sentence it also says that choice filtering (emphasis mine):
won't limit the amount of data sent to each device but it can significantly reduce the amount of options shown to each user and can help speed up lookup expressions.
So, a choice filter can filter the options shown to the enumerator. It doesn't require, but can use an instance lookup if the filter is more complex.
@LN perhaps a para break/minor edit to make it clearer? eg
For now, you can limit the Entities that are available from a select_one_from_file using a choice_filter.
A choice filter won't limit the amount of data sent to each device but it can significantly reduce the amount of options shown to each user and can help speed up lookup expressions.