How can I stop (early exit) randomized block (or loop and merge) under certain condition? | XM Community

How can I stop (early exit) randomized block (or loop and merge) under certain condition?

  • 15 November 2022
  • 2 replies
  • 250 views

Badge +1

Hello. I'm having trouble because the randomization function overrides the display logic/skip logic/survey flow function.
What I'm trying to do is to show six images (2 images at a time, the order of six images is randomized) and stop showing the images once a participant chooses one of the images. Currently, I ask "Are you willing to accept either one of the offer?" and want to skip the rest of the images and move to the next block. So, some participants will make a decision on the second round (see 4 images and do not see the rest 2 images) and some participants will make a decision on the final (third) round (see all 6 images).
If doesn't matter whether I use the randomization function in the block or loop and merge function as long as I can make the survey work as I explained. I tried both. However, as the randomization or loop function override survey flow/display logic/skip logic, I could not figure out how to stop participants from seeing the rest of the images once they decide to choose one of them.
Here is the survey to help your understanding. Currently, participants go through all three rounds no matter what answer they choose on the question. https://uiowa.qualtrics.com/jfe/form/SV_bQOy6dWegMuC4D4
I referred to this thread and tried java script on loop and merge.
https://stackoverflow.com/questions/25766238/prematurely-exiting-a-loop-and-merge-block-in-qualtrics
Qualtrics.SurveyEngine.addOnload(function ()
{
this.questionclick = function(event,element)
{
console.log(event,element);
if (element.type == 'radio')
{
var choiceNum = element.id.split('~')[2];
if (choiceNum == 2)
{
Qualtrics.SurveyEngine.setEmbeddedData("EndLoop", choiceNum);
}
}
}
});
This is the code I tried. It didn't work as described.
Can anyone help me with the premature exit of the randomized block/loop&merge? It doesn't matter how it is achieved (survey flow, javascript, etc.) but I have zero knowledge in developing.
Thank you so much in advance!


2 replies

Userlevel 5
Badge +25

Hi SJeong,
You should be able to solve this using display logic and a loop and merge. If all of the questions within a loop and merge set to be hidden, it will advance out of the loop. So all we need to do is set up your "Yes" choice to tell the display logic to hide the questions once it has been selected.
In Survey Flow:
Set an embedded field which we will call "Skip" and set it to 0:
image.pngIn your survey block:
Set up a loop and merge to randomly repeat however many times.
Set display logic to only display questions when Skip equals 0
image.pngAdd the following Javascript to your multiple choice question:
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
    var SelectedChoices = this.getSelectedChoices();
    if(SelectedChoices == 1) {
Qualtrics.SurveyEngine.setEmbeddedData("Skip", 1);
}
});

If all works correctly, selecting "Yes" should set the Skip variable to 1 after submitting the multiple choice question. When the loop begins its next iteration, it will check the Skip variable and hide all questions, automatically moving out of the loop to the next correct block.
Good luck!

Badge +1


Hi @bgooldfed
Thank you so much for your reply. I tried the way you suggested and it didn't work. The survey still loops even if I choose "Yes" option.
This is how l set the survey flow, loop&merge, Java script as you provided, and making sure that the value of "Yes" is set to 1. Did I make a mistake? Do you see any reason why it didn't work? I think the display logic was not a problem because I didn't see any loop&merge block when I moved the embedded data block to lower than the loop & merge block.
If you don't have an answer, still, many thanks for your time and effort. I appreciate it.
image.pngimage.pngimage.pngimage.png

Leave a Reply