When filling out your form, you may come across an indexed-repeat() error. The exact wording will vary, but it looks something like this:
Error evaluating field 'paid_taxes': The problem was located in Relevant expression for /indexed_repeat_error/paid_taxes This field is repeated: /indexed_repeat_error/hh_rep[1]/hh_income[1] /indexed_repeat_error/hh_rep[2]/hh_income[1] /indexed_repeat_error/hh_rep[3]/hh_income[1] /indexed_repeat_error/hh_rep[4]/hh_income[1] You may need to use the indexed-repeat() function to specify which value you want.
Table of Contents |
1. About indexed-repeat() errors
This error occurs when you attempt to reference a repeated field outside of its repeat group without a supporting function. When you try to do this, the form does not know which instance of the repeated field to use. Does it use the first instance, the second instance, does it check all values, or something else? The form doesn't know, so it throws an error.
2. Diagnosing the error
The first step is to look at the error message you receive, and check what field in the form is causing the error message.
2.1 Understanding error messages
Take a look at the error message for this sample form, since it will give you valuable insight into what to look for:
Error evaluating field 'paid_taxes': The problem was located in Relevant expression for /indexed_repeat_error/paid_taxes This field is repeated: /indexed_repeat_error/hh_rep[1]/hh_income[1] /indexed_repeat_error/hh_rep[2]/hh_income[1] /indexed_repeat_error/hh_rep[3]/hh_income[1] /indexed_repeat_error/hh_rep[4]/hh_income[1] You may need to use the indexed-repeat() function to specify which value you want.
Notice these important points in the error message:
- Field with error: It says there is an "Error evaluating field 'paid_taxes'", so the issue is that the field "paid_taxes" is referencing a repeated field without the proper function.
- Property with error: It says "The problem was located in Relevant expression", so the issue is with the relevance property of the field "'paid_taxes'".
- Referenced field causing error: It says the field "hh_income" is repeated, so the issue is that the field "hh_income" is being referenced without the proper function.
So, from that error message, we know the issue is that the repeated field "hh_income" is referenced in the relevance property of the field "paid_taxes", which is outside of the repeat group "hh_income" is in. We now know exactly where to look!
2.2 Finding the field with the error
The error message may not always tell you where the error is occurring, so it may take some investigating.
Note the name of the field being referenced in the error message. Find which repeat group it is in. Find where that repeat group starts and ends.
Once you know where its repeat group starts and ends, find where that field is being referenced outside of its repeat group, without a function for referencing repeated data. That is where the issue is being caused, and where it needs to be fixed.
2.2.1 Example
In the sample form, because of the error message, we know the issue is that the field "hh_income" is being referenced outside of its repeat group. That field is in the repeat group "hh_rep" that goes from rows 13-17. So, to find where the issue is, we can search for all references to the field "hh_income", but we can ignore field references on rows 14-16, since all of those would be in the same repeat group, which would not cause an indexed-repeat() error.
If you are working in a spreadsheet form definition, when searching for the field reference causing the issue, be sure to not just check the survey sheet, but also the choices and settings sheets. Use your spreadsheet application's search tool to help you find the field and field references.
By searching for references to the field "hh_income", we were able to find which field was causing the error!
If you are working in the online form designer, you can use the Search button on the top bar to help you find the field and field references.
3. Fixing indexed-repeat() errors (with examples)
Whenever you reference a repeated field outside of its repeat group, you need to determine which repeated value you need for your new field. Do you need the FIRST value, the LAST value, do you need to check ALL values, or something else?
To fix this error, instead of referencing the repeated field directly, you need to use a function that can work with repeated data. For help determining how to properly reference the repeated field, check out our support article Using and referencing repeated data.
3.1 Example
Let's take a look at another example. Check out this sample form, (it has default values added so you can easily test it, but default values are not required in your actual form). If you add it to your server and try to fill it out, on the last field, you will get this error:
This field is repeated: /indexed_repeat_error/hh_rep[1]/hh_income[1] /indexed_repeat_error/hh_rep[2]/hh_income[1] /indexed_repeat_error/hh_rep[3]/hh_income[1] /indexed_repeat_error/hh_rep[4]/hh_income[1] You may need to use the indexed-repeat() function to specify which value you want.
According to this error message, the field "hh_income" is being referenced, but the field reference is outside of its repeat group. The form doesn't know which value of the field "hh_income" to use, so there is an indexed-repeat() error.
The reason that error is appearing is because the field "taxes_paid" has this constraint:
. <= ${hh_income}
However, the field "hh_income" is a repeated field. When that constraint expression is attempting to determine if the response is valid, it goes to check the value of the field "hh_income", but it does not know which of the four values to use. Does it use the first value, the second value, does it check all values, or something else? The form does not know, so it throws an error.
First, you need to determine which value of the field "hh_income" you want. Do you want to check all values? Individual values? How do you want to check them?
3.1.1 Fix 1: Check all values of a repeat group
Let's say you've thought about how you want to reference the field "hh_income", and you want to make sure the value entered in "taxes_paid" is less than the SUM of all values of the field "hh_income". For example, if one household member has an income of 25,000, and another has an income of 30,000, then the field "taxes_paid" should have a value less-than-or-equal-to 55,000.
Since we want the sum of the values of "hh_income", we can use the sum() function in our constraint, like this:
. <= sum(${hh_income})
As mentioned in part 2, the sum() function is a function that can be used on repeated fields, so you can use it to reference fields outside of their repeat groups. In this case, the sum() function takes every value of the field "hh_income", and adds them together. That way, the constraint expression can make sure the taxes paid are less than the total household income.
3.1.2 Fix 2: Check individual values.
Maybe you don't want the total household income tax paid, but you want the INDIVIDUAL taxes paid by each household member. Since you will be repeatedly asking for the taxes, the field "taxes_paid" should also be a repeated field.
The easiest way to set this up is to simply move the field "taxes_paid" to the repeat group, and that will work perfectly well! That way, you don't even have to use a function for repeated data, since the field reference will already be in the same repeat group.
Another option is to add a second repeat group, and then use the indexed-repeat() function to reference each field from the previous repeat group. This is helpful if you prefer to keep the repeated data in separate repeat groups.
3.2 Repeated fields in labels
You cannot use expressions in field labels nor choice labels. If you would like to display the value of a repeated field, add a calculate field outside of the repeat group with a calculation that references the field in a function that works with repeated data. Then, reference that calculate field instead of the repeated field.
For example, let's say you have this field label:
How old is ${hh_name}?
However, "hh_name" is a repeated field in the repeat group "hh_rep", which means there will be an indexed-repeat() error. To fix this, you will need a function that can reference repeated data. Let's say you want the value of the first instance of the field "hh_name". First, outside of all repeat groups, add a calculate field with this calculation:
indexed-repeat(${hh_name}, ${hh_rep}, 1)
We will call that field "hh_name_1st". You can then reference that calculate field instead of the repeated field:
How old is ${hh_name_1st}?
Note: This is just an example; it is uncommon to use an indexed-repeat() function where the third argument is a static value such as 1; a field reference is more common, like this:
indexed-repeat(${hh_name}, ${hh_rep}, ${index})
Do you have thoughts on this support article? We'd love to hear them! Feel free to fill out this feedback form.
0 Comments