Repeat Group Displays Blank For First Item in CommCare Case Display inside repeat

Goal:

I have 10 household_test cases. Each case has several properties:

  • hh_id
  • hh_full_name
  • age
  • sex
  • phone_number

I want to run through these cases one-by-one in a repeat group so I can mark attendance (Present/Absent) for each household member. On each screen, I want to see just one person’s hh_full_name, choose Present or Absent, then go to the next person.

What I built:

  1. Hidden value outside repeat:
  • Name: hh_count
  • Calculate: count(instance('casedb')/casedb/case[@case_type = 'household_test'])
      • This correctly returns 10.
  1. Repeat group:
  • Repeat count: hh_count
    Inside the repeat:
  • Hidden value hh_member_name** to pull the name for this repeat iteration:
  • instance('casedb')/casedb/case[@case_type = 'household_test'][position() = position(current()/../..)]/hh_full_name
    • Multiple choice question :
    • Label text: Mark Attendance for
    • Choices: Present / Absent

The issue:

  • hh_count works fine (returns 10).
  • In the repeat, the first screen’s name is blank (but the case property is not actually empty).
  • The subsequent 9 iterations show the correct names.
  • The total shown is 9 names, because the first iteration is blank.
  • I checked with a label showing position() inside the repeat — it goes from 0 to 9. That’s why the first one is blank (index 0).
  • If I display the list of cases outside the repeat (using a multiple choice lookup), all 10 names appear correctly.

Help needed:

I need a way to display hh_full_name for each household_test case inside the repeat so that:

  • First screen shows the first person’s name (no blank)
  • Attendance can be marked Present/Absent
  • The process continues for all 10 household members without skipping anyone.

I have also tried to use position(/..) and position(current()/../.. but the issue is the same

@yahye159
Hello,

This is my recommendation based on my experience using repeat groups:

Outside of the repeat group you need 2 hidden values:

case_ids_of_interest - calculation: join(" ", instance('casedb')/casedb/case[@case_type = 'household_test']/@case_id)

count_case_ids - calculation: count(case_ids_of_interest)

Within your repeat group you then use the position() function as you've been doing and simply retrieve the case_id at that position from case_ids_of_interest. From there you can retrieve the applicable fields associated with that case_id using the queries. The join function used to create the case_ids_of_interest works since it is a space-separated list similar to those that CommCare generates for multi-select question types, which allows you to use the selected-at function to retrieve the case_id. Also case_ids themselves do not have any spaces. You cannot have the retrieved values that are being concatenated together also include spaces (for example, a name with spaces). If those values themselves include spaces the count() function and selected-at() function cannot be reliably used to retrieve desired values.

Thank you Achavez812, I will check it an dcome back to you.

sounds like you need to add 1 to your position calc.

Hi Mazz,

Yeah when added +1, it is working for me as per the below screenshot. Let me know if there is a better way to do it. Thanks

hidden value “name”: instance('casedb')/casedb/case[@case_type = 'household_test'][position() = position(current()/..) + 1]/hh_full_name

as long as you are getting all the details for all the repeats, and you don’t have issues, don’t change it :smiley:

glad it worked out

to explain, position() is zero-indexed. which means that the first element is 0.

repeat groups are indexed from 1 if I remember correctly “I have not built an app in a couple of years”

so the total repeat count will be 10, but the last item will be #11 because it started with 1 and not 0.

Thank you brother, you’re right.

Hi yahye,

Just keep in your mind after you went through all names then you click submit, you can't edit the attendance sheet even through follow up form, unless you create subcases when you submit the first form.

Best,

Hossam