Loop and merge from known data | XM Community
Skip to main content
Hello,

I was hoping to get some help with loop and merge.



We are conducting a scientific research study, where at baseline we asked participants how many children and adults live in their house, and collected the initials for each of those children and adults and also collected data on each individuals fruit and vegetable consumption. We know the ID number of each participant and have initials for all people in their household.

We are now at the mid-point of the study, and want to ask the for each participant and for all the members of their household (as per the data collected at baseline) about their fruit and vegetable consumption.



Is it possible to set something like this up (and if so, how to do the loop and merge)?

- a drop down list with the ID number for the participants.

- based on that ID number, show only the household member initials that are associated with that participant

- Based on that ID number, ask 4 questions for each person in their household, by displaying the initials for the people in the household automatically (without the participant having to enter the initials again)? For example

- - Select participants ID number (in this example participant selects 12JBJ, and this participant has 2 children TK and AK (which we know based on the baseline data collection))

- - How many fruit servings does TK eat (TK being the initials of a child associated with a participant whose ID is 12JBJ, and "TK" is automatically inserted)

- - How many vegetable servings does TK eat (TK being the initials of a child associated with a participant whose ID is 12JBJ, and "TK" is automatically inserted)

- - Would you like TK to eat more fruit (TK being the initials of a child associated with a participant whose ID is 12JBJ, and "TK" is automatically inserted)

- - Would you like TK to eat more vegetables (TK being the initials of a child associated with a participant whose ID is 12JBJ, and "TK" is automatically inserted)



How many fruit servings does AK eat (AK being the initials of a child associated with a participant whose ID is 12JBJ, and "AK" is automatically inserted)

- - How many vegetable servings does AK eat (AK being the initials of a child associated with a participant whose ID is 12JBJ, and "AK" is automatically inserted)

- - Would you like AK to eat more fruit (AK being the initials of a child associated with a participant whose ID is 12JBJ, and "AK" is automatically inserted)

- - Would you like AK to eat more vegetables (AK being the initials of a child associated with a participant whose ID is 12JBJ, and "AK" is automatically inserted)



Not all participants have the same number of members living in their household (ranging between 2 to 15 people). We have the data on number of members and each members initials currently in a spreadsheet (1st column ID number, then up to 15 columns with the initials for each member in that person's household)



Thank you, in advance

Anette
Yes, you can do this:

1. Set up a MC question before the loop where you pipe in the family member ID's as choices. You'll have to have the maximum possible number of choices (15).

2. Add display logic to the answer options to only display the answer option if the family member exists.

3. Hide the question with JavaScript: `jQuery("#"+this.questionId).hide();`

4. Loop based off the hidden question you just created. Pipe in other information (e.g. initials) in Field 2, Field 3, etc.

5. Pipe the loop/merge fields into your loop questions (e.g. initials = ${lm://Field/2}).

Leave a Reply