External CSV Not Iterating Through Multiple Records in Repeat Group - Only Pulling First Record

I am building an XLSForm to conduct follow-up surveys on action points previously assigned to health facilities. My form needs to dynamically display multiple action points per facility based on data from an external CSV file.
Form Structure:
I have an external CSV file named action_points.csv with the following columns:
action_point_id (text)
label (text) - the actual action point description
facility_name (text)
point_index (integer)
Multiple action points are mapped to each facility (e.g., "Kalabo District Hospital" has 3 action points, "Lukulu District Hospital" has 5, etc.)
What I'm Trying to Achieve:
User selects a facility from a dropdown
Form counts how many action points exist for that facility
A repeat group automatically iterates through ALL action points for the selected facility
Each iteration displays the specific action point label and asks follow-up questions (completed? if not, why? expected completion date?)
The Problem:
When I use the pulldata() function to retrieve action point labels within the repeat group, it only pulls the first action point associated with the selected facility, regardless of which iteration of the repeat I'm in. The repeat count is correct (e.g., if a facility has 5 action points, the repeat runs 5 times), but the same first action point label appears in all iterations instead of cycling through each unique action point.
What I've Tried:
Using pulldata('action_points', 'label', 'facility_name', ${facility_name}) - this only returns the first matching record
Using index() within calculations to try to reference different rows
Filtering with multiple criteria including point_index
What I Need:
I need a way to iterate through multiple matching records from the external CSV file within a repeat group, so that each iteration of the repeat displays a different action point (label) for the selected facility.
Is there a way to use pulldata() with an index/position parameter, or should I be using a different approach like instance() with XPath predicates? Any guidance on the correct syntax would be greatly appreciated.
Attached:
My XLSForm file
Sample action_points.csv file

action_points.csv (11.9 KB)

action_points_followup.xlsx (11.9 KB)

As your file does have an AP integer index # beginning with 1 for each facility, and you can count the number of APs per facility correctly, you could look up each one matching the repeat position with the index #.

eg:

  • put a calculate field in the repeat like ${repeat_index} with a calculation position(..)
  • have another calculate that gets the AP text like instance('action_points')/root/item[facility_name = ${facility}][${repeat_index}=point_index]/label
  • and another that replaces label with action_point_id

But if you make an error in the point index (skip or duplicate a value) it will break, so you could be fancy and ignore the index value completely and simply pull the values in the order they exist in the file where list order value = repeat position value, eg:

  • have a calculate that gets the AP text like instance('action_points')/root/item[facility_name = ${facility}][position()=position(current()/..)]/label

Some of what I was trying recently might also help you, as I was dynamically building and populating repeats:

BTW: your facilities choice list has spaces in it, it would be better to remove these as spaces are used to separate select multiples, nodesets etc.