Dynamic data attachment breaking

Hello,

I am having some trouble creating dynamic data attachments. I have successfully linked the parent and child forms, and the first few questions in the child form now auto-fill with responses from the parent form. But as soon as I get down to the second group of questions (1. Strategic Vision and Plan), this seems to break and the fields do not auto-fill. I have a feeling this has something to do with the groupings but am not well enough acquainted with dynamic data attachments to be able to figure it out!

I’m attaching the parent and child xls forms, and the new (child) survey is here: Enketo Express for KoboToolbox

KYN 2025-26 child for dynamic data attachment.xlsx (33.9 KB)

KYNAnnualSurvey2024-25 - PARENT.xlsx (31.8 KB)

(For background: our partner networks complete this form on an annual basis. We have updated the form slightly for this year and so I’ve cloned and redeployed it. We want to make it easier for our partner networks to complete, by pre-populating most of the form with last year’s responses when they enter their network name)

Any help appreciated!

Spot on! :slightly_smiling_face:

If you look closely at your form, the first group of questions (group_el5wy41) appears to be filling in OK with the data looked up from the parent form:

For example, the Country_of_Network has a lookup function of:

instance('KnowYourNetworkAnnualSurvey')/root/data[group_el5wy41/Network_Name= current()/../networkname2026]/group_el5wy41/Country_of_Network

This basically say lookup in instance('KnowYourNetworkAnnualSurvey') (ie the parent DDA file) the record where the field group_el5wy41/Network_Name matches the value in child form

current()/../networkname2026

[aside - you happen to be using identical group names in both your parent and child form, which may be confusing you… they are in fact entirely different entities!]

This requires a little explanation:

  • the current() references the current question (actually the current XML element), namely Country_of_Network.
  • the following /../ tells it to go up one level in the XML hierarchy, which is the enclosing (child form) group group_el5wy41.
  • and the networkname2026 references the peer question within the same group.

This is basically how you reference another question in the same group. All good so far.

However, if you look at ostensibly the equivalent question in the following Strategic Vision and Plan group, the lookup function (in red) is:

instance('KnowYourNetworkAnnualSurvey')/root/data[group_el5wy41/Network_Name= current()/../group_el5wy41/networkname2026]/group_zx9yw06/In_the_last_5_years_the_local_responses

Similar to before:

  • the current() references the current question, now sitemapping.
  • the following /../ tells it to go up one level in the XML hierarchy, which is the enclosing group, now group_zx9yw06.

But the following group_el5wy41/networkname2026is now basically telling it to look for a subgroup called group_el5wy41 that is inside group_zx9yw06 . Which obviously doesn’t exist!

Basically, if you want to reference a value from within a group that is in another group, you actually have to go up two levels - ie up to the grandparent (which in this case if the root level of your form) - to then drill back down two level to the desired field. ie try this instead:

instance('KnowYourNetworkAnnualSurvey')/root/data[group_el5wy41/Network_Name= current()/../../group_el5wy41/networkname2026]/group_zx9yw06/In_the_last_5_years_the_local_responses

Note the /../../ which goes back 2 levels in the XML hierarchy. You will probably need to do this all over the place to get to your networkname2026 value.

Hopefully that makes a little more sense; I know these XPath things can be rather confusing (if not impenetrable :shaking_face: )

Thanks so much - I have gone back through and corrected this, and it is all now working!!

1 Like