Repeat group issue

I have a form that register a mother and her children. I used a repeat group to register children in cases where a mother has more than one child.

When capturing the details on phone, i end up with the following error. The first child details id captured om but when looping in for the next child is when the error below pops up. Your support is most appreciated.

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

That error sounds like you have a hidden value "/data/days_since_birth_1" outside of the repeat group, which references a question inside the repeat group. This can only be done with some special considerations. You can read more about that here: https://confluence.dimagi.com/display/commcarepublic/Using+Repeat+Groups+in+the+Form+Builder#UsingRepeatGroupsintheFormBuilder-LogicOutsideTheRepeatGroup

You may alternatively want to use the join() function to combine the values from each iteration of the repeat group.

Thanks Ethan_Soergel your prompt response. I have gone through the two solutions options suggested. When comes to any of them, I have not used this before and can not figure out how to put in the syntax into the codes. How do I use join function with repeat functuion, at what point do I bring it in?. I would appreciate if you could even have time to connect with you via skype, just assist understand this better.

Kind Regards

Andrew

Hi Andrew,

Sorry, I don't have availability to do a call. The way to use join is to change the calculate expression for your days_since_birth_1 question from

#form/children_registration/dob

to

join(" ", #form/children_registration/dob)

That will join all the dates of birth together into one value, separated by a space.

If you're new to CommCare, I'd highly recommend reading through some tutorials. Here is a list of tutorials related to app building - the "Hidden Value Calculations Tutorial" is a good introduction for this sort of issue.

https://confluence.dimagi.com/display/commcarepublic/Application+Building+Tutorial+Series

  • Ethan

Many thanks Ethan_Soergel. I have used the join solution as you advised.

The error I'm getting now is :
Calculation Error:
Error in calculation for /data/days_since_birth_1 converting string 2019-03-05
to date

My calculation for "my days_since birth_1" " today() - date(join(" ", #form/children_registration/dob)) < 30"

Thanks for your support.

Do you intend to only do this calculation for the first child in the repeat group? If you want to do it for all child, I'd move this calculation inside the repeat group, then you won't need to use join(). To work with only the first child, you should access the question by count, as described in the documentation. You'll also probably need to make sure there's at least one child, so it'd look something like:

if(count(#form/children_registration/dob) > 0, today() - date(/data/children_registration[1]/dob) < 30, '')

Ethan,

Thanks a lot for the information provided. It helped figure out the issue and now it is sorted

Another issue, for your kind support, if possible, I'm trying to save the questions under Repeat group to property so that I can use the saved values on other parts of the application ( other forms) but for some reason I can not see any questions under the Repeat group. Other question outside the repeat group I can see all. Do you have any suggestions why this could be the case ( not able to see them in order to save ) ? Your support, as usual is much appreciated.

Regards

Andrew

Hey Andrew

Check this thread out