Repeat Group Error

Hi,

I'm working on a form that has 3 repeat groups:

  1. How many mothers live in this household, and ask a set of questions to each mother;
  2. How many children live in this household, and ask a set of questions to each child;
  3. Give a treatment to each of the children.

The first repeat group (mothers) works well. When testing the second repeat group (children), the first child's info is captured, but when I enter data for the second child, the error message below popped up:

Display Condition Error: Error in calculation for /data XPath nodeset has more than one node [/data/repeat_group_children[1]/treatmentConsent[1];/data/repeat_group_children[2]/treatmentConsent[1]]; cannot convert multiple nodes to a raw value. Refine path expression to match only one node.

treatmentConsent is a question in the children repeat group- we ask if we can treat the child and if yes, we start to treat. So it triggers the treatment repeat group. And the error message disappears when I remove the treatment repeat group.

you need to have a reference that returns only a single value in display conditions.

this link should help you out

https://confluence.dimagi.com/display/commcarepublic/Advanced+Functions+for+Repeat+Groups

Hi Mazz, I carefully read through the page but I'm a bit lost. Is "Model Iteration inside of a Question List" the part that is related to my question? I didn't find information about have a single value in display conditions either :cry:

i don't know what your form is or where you code that's triggering the error is
but this error usually happens when you are using a function or putting your code somewhere that expects a single value.

when referencing elements inside a repeat, this can happen.
you need to use current() function
the advance functions for repeat groups explains how to use current() and parent ".."

if you are for example using a concat function with a name inside the repeat, the concat function doesn't work if you give it an element inside the repeat after you add a 2nd one. because the reference you made to the element inside the concat function is getting 2 names, instead of 1.

so if you first name is called first_name inside the repeat, you would need to use concat like this

concat(current()/../first_name, ' ', current()/../last_name)

using #form/repeat_name/first_name will return 2 first_names when you have 2 repeats, 3 when 3, etc...
that's why this type of error shows up most of the time
if you have a display condition for example first_name = 'name' then it'll be trying to use the "=" sign for a set of values on 1 side, and a single value on the other. that doesn't compute

Thank you so much for the detailed reply, Mazz! I have solved the issue.