Populating Loop & Merge fields with the selected choices from another Loop & Merge question | XM Community
Solved

Populating Loop & Merge fields with the selected choices from another Loop & Merge question


I have a survey with a Select Any question, Q1, in a Loop & Merge block, B1. I'd like to then have a follow-up Loop & Merge block where the fields are the selected choices of Q1 from a particular loop from the previous block, B1.
Is there a way to populate the selected choices of a particular loop into the fields of a subsequent Loop & Merge?
What I've tried so far:

  • Use the built-in "Loop based off of a question" functionality: this will allow me to select Q1, but doesn't allow me to specify which loop to populate selections from.

  • Playing around with piped text: My understanding is that this reference (${q://1_QID1/ChoiceGroup/SelectedChoices}) will pipe in the selected choices of the first loop of Q1. However, I haven't been able to figure out where I could place this to get the selected choices to populate the fields of the Loop & Merge block.

  • icon

    Best answer by katiekoehler 30 May 2020, 01:38

    View original

11 replies

I should add: I plan to make a subsequent L&M block for every loop of Q1 in B1 (180 in total), each referencing the selected options to Q1 from one of the loops in B1. If the solution will work for a copied version of the subsequent blocks without requiring much manual configuring for each of the 180 follow-up blocks, that would be ideal.

Userlevel 7
Badge +27

I think this will be a lot to set up no matter how you do it.
You can create a MC question for each of the B1 loops that has the same choices as Q1. On each choice add display logic to only display the choice if it was selected in the B1 loop of interest. Hide these questions with JavaScript. Then base the follow-up loops on the displayed choices in these questions.

I've never used custom code with Qualtrics -- do you happen to have a feel for whether this is something that could be more easily solved with Javascript if I took the time to look into it?

Userlevel 7
Badge +27

katiekoehler - There is no way to control the loops of a loop & merge with JavaScript, but it could help streamline the process I outlined above. Instead of setting up choice display logic on all the choices in the hidden MC questions as I described above, you could pipe in the selected choice recodes into JavaScript, parse them, select the same answers as in the loop, then base the loop & merge on the selected answers in MC.

That seems like it could be more efficient than my backup plan of breaking the first loop and merge out into 180 blocks. Any pointers on where to learn more about populating the choices of a MC question with Javacsript? Thank you for all your help so far!

Userlevel 7
Badge +27

katiekoehler - You wouldn't be populating the choices of the MC question, you would be selecting them. You would use setChoiceValueByRecodeValue from the Qualtrics JS Question API.

Ah I see! Thanks TomG. I've been trying out various versions of something like this:
Qualtrics.SurveyEngine.addOnload(function()
{

var selections = "${q://92_QID325/SelectedChoicesRecode}";
var selectionArray = selections.split(",");
var i;
for (i = 0; i < selectionArray.length; i++){
this.setChoiceValueByRecodeValue(selections[i], true);
}
});
It doesn't seem to be working. Any pointers?

Figured out the issue. It was a combination of 1) the recode values for the question that my JS was attached to getting totally out of whack (must have happened when I was troubleshooting) and 2) selections[i] in the loop should be selectionArray[i] (see corrected code snippet).
Qualtrics.SurveyEngine.addOnload(function()
{

var selections = "${q://92_QID325/SelectedChoicesRecode}";
var selectionArray = selections.split(",");
var i;
for (i = 0; i < selectionArray.length; i++){
this.setChoiceValueByRecodeValue(selectionArray[i], true);
}
});
A couple tips for others... for posterity:

  • Qualtrics documentation says that setChoiceValueByRecodeValue takes a string as input for the recodeValue parameter, but it actually takes integers

  • Check your recode values regularly when you're troubleshooting

TomG I implemented this solution today by creating 180 hidden questions and attaching the above Javascript code to them (each referring to a different loop in the previous Loop and Merge question). When I test this out, the page with all the hidden questions takes about 20 seconds to load.
Do you happen to know of any ways to optimize the load time for a page like this, or any workarounds to avoid this?

Userlevel 7
Badge +27

Any performance improvement would be negligible.
I would split them out into separate blocks, one before each loop it applies to. It will be a lot less noticeable that way.

Ah, yes good idea! I can't have the hidden question within the second loop and merge block, so I'm creating a separate "setup" block before each of the subsequent loops and merge blocks. Within the setup block, I'm putting the question that I populate with Javascript. I have that question set to be hidden and automatically click the next button using Javascript.
For some reason, two small boxes with up/down arrows show up in near where the "next" button would be. I can't figure out what they are or where they're coming from. Any tricks to get that transition to be more seamless? This is my code:
Qualtrics.SurveyEngine.addOnload(function()
{
jQuery("#"+this.questionId).hide();
this.hideNextButton();
var selections = "${q://1_QID325/SelectedChoicesRecode}";
var selectionArray = selections.split(",");
var i;
for (i = 0; i < selectionArray.length; i++){
console.log(i);
this.setChoiceValueByRecodeValue(parseInt(selectionArray[i]), true);
}
this.clickNextButton();
});

Leave a Reply