How do I set the number of loops in a Loop and Merge based on an Embedded Data object? | XM Community
Solved

How do I set the number of loops in a Loop and Merge based on an Embedded Data object?

  • 25 September 2019
  • 6 replies
  • 547 views

Badge
I send my surveys out as anonymous links with embedded data appended at the end. I'd like to pass in a numeric value which is used to manage a Loop and Merge as if it were a question answer. Example:

I have participant data indicating how many children they have. I would like to pass the number of children value in <<anonymous link>?children=X. Then, in my survey, I loop based on the value of the children Embedded Data object.

Any thoughts on how to accomplish this?
Thanks!

FYI: I've got a bit of scripting knowledge, so could try to pick up enough .js to make this happen. But would prefer to use the GUI.
icon

Best answer by KimothiSaurabh 26 September 2019, 10:37

View original

6 replies

Userlevel 4
Badge +18
@muriah - There might be two approaches to achieve this:-

Create a loop merge block with maximum possible number of iterations and add display logic for each question in this block based on embedded data. For example if we can have maximum 10 children for a respondent, create loop with 10 fields and the add below display logic in each question. Here, "NoOfchild" is embedded variable storing number of children and ${lm://CurrentLoopNumber} denotes the current loop.

!

If you have too many questions in loop above approach may be tedious so alternate would be to create a numeric question and set loop-merge based on response of this question. You will have to set response of this numeric question from embedded variable.
Badge
Thanks. I hadn't considered the display logic route, but that seems like a work around for this specific scenario (up to 5 loops). However, I'd prefer to take option 2. However, I haven't seen how to default a multiple-choice question to the value of an Embedded Data object. Would I simply use a text field with numeric validation?
Userlevel 4
Badge +5
!
As an edo you could just use ${e://Field/variable} to get the value of the variable for the answer option.
Badge
@KimothiSaurabh
I think I'm missing something basic.

I've created a simple test survey with 1 embedded data object (answer). The Question 1 is a text field with numeric validation. I've set the default value of Question 1 to the content of the "answer" embedded data object. I've also added display logic to Question 1 so it only appears if the "answer" embedded data object is empty (I don't want my participants to see the loop control question if I can help it.)

I've set a simple loop based off of Question 1 with a maximum number of loops set to 100.

When I preview the survey without passing anything into the "answer" embedded data object, I fill out the question and the loop works as expected.

However, when I pass in any value to the "answer" embedded data object, the loop doesn't trigger. I assume this is because the answer in Question 1 doesn't actually get stored unless I display Question 1 to in the survey (I removed the display logic, and the loop worked).

Any obvious things I'm missing?
Userlevel 4
Badge +18
@muriah - I guess you are proceeding with second approach. If loop works as expected when you fill out the question then issue is with the display logic. If you skip any question using display logic, Qualtrics will not store data for that question hence loop will not works as expected. To avoid this, remove display logic from that question and add below script in javascript of that question. This script will set response of it from embedded data (NoOfchild) and hide the question from link so respondent will not see it.

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery('input[id*='+this.questionId+']').val("${e://Field/NoOfchild}")
jQuery('#'+this.questionId).hide();
this.clickNextButton();
});

Hope this helps.
Badge +1

https://community.qualtrics.com/XMcommunity/discussion/comment/18143#Comment_18143I'm facing this exact same problem. muriah -- were you able to figure this out?

Leave a Reply