Use of previous answer working erratically

Hello,

I’m building a form to conduct facility/school assessments. At the beginning I’m asking for the name of the facility (text entry) and lower in the form I have a repeating group where information on individual buildings at the facility can be detailed. So respondents can add as many buildings as they need.

For each building (or group) I want to include the name of the facility to which it belongs (I know this is indexed, but it makes working with the data afterwards more intuitive). The way I have set it up is with a hidden question inside the repeating group, for which the default response references back to the response given to the facility name question with the ${facility_name} code.

For some reason, the first entry of this group doesn’t store the referenced facility name, but the second added and subsequent groups do and it works great from there on. But the response of the hidden question of the very first group is always blank. Same behaviour if it’s not a hidden field.

Help welcomed.

Welcome to the community, @Margoye! Would you mind sharing your xlsform with the community? Maybe the community could help you solve your issue.

Hi Kal_Lam, thanks for reaching out. Below is a link to the xlsform. The “facility_name” field is one of the very first and the repeating group is the one called " Building information". For debugging purposes I added a text field to inject the previous answer, but it’s the hidden field at the beginning of this group that I need to get working correctly.

Draft Disaster Preparedness Assessment

Thanks in advance.

Kind regards,
Marcel

Hi @Margoye, this does seem to be a potential bug — thanks for bringing this to our attention. Can you try doing to following to get your desired result as a workaround:

Your current line 54:

type name label::English (en) hint::English (en) required default calculation
hidden parent_facility Parent Facility false ${facility_name}

Suggested change:

type name label::English (en) hint::English (en) required default calculation
text parent_facility ${facility_name}

This is based on the XLSForm docs here:

The calculate type calculates text but calculations can also be added to any other question types. Non-text types can be useful for data analysis, e.g if a date or date-time is calculated. If no label and no hint is included, the calculation will be hidden.

1 Like

Hi @Josh , thanks for the hint. With the suggested workaround the value is correctly stored for all entries in the repeating group.

Much appreciated.

Marcel.

2 Likes

@Margoye great! For reference, it seems this is the expected behaviour of default values and repeat groups:

You can also add a default calculation, which will only be calculated only once when the form loads or - if the question is inside a repeat - when the repeat is added.

This explains why the first instance of the repeat does not populate the default value — as it wasn’t accessible on the initial form load — and why subsequent repeats do have access to it. So in the future, rather use the approach I suggested above.

1 Like

Well noted. Thanks!

2 Likes