Record Loop and Merge Fields | XM Community
Solved

Record Loop and Merge Fields

  • 17 March 2021
  • 3 replies
  • 413 views

I am trying to randomly display and keep track of three videos I show to participants.
The videos are split into three categories, Novice, Intermediate, and Expert. I currently have it so that a Randomizer block randomly chooses one out of three question blocks. The questions blocks are identical except for the data stored in their Loop and Merge. The Novice block contains videos with score below X. The Intermediate block contains videos with score higher than X but lower than Y. The Expert block contains videos with score higher than Y.
Each of these blocks need to show three random videos from the Loop and Merge data. Field 1 of this data stores the score of the video shown, and Field 2 has the embed link that I embed into the code block.
I was going to store the data through javascript with the following:
var score = parseInt("${lm://Field/1}");
Qualtrics.SurveyEngine.setEmbeddedData("condition", "Z");
Qualtrics.SurveyEngine.setEmbeddedData("scoreVideo", score);
where Z is the condition of the block. However, I realise if I loop through 3 times, it will overwrite the embedded data. I guess my question is two fold:
1) Is there a better way of doing this such that I can every video on the same page without needing set up Loop and Merge data that contains a row for every video shown (I'll have around 20-30 videos for each condition, meaning for a combination of any 3 videos without replication would be 4060 without order or repetition)?
2) How can I keep track of what loop I'm on in the Loop and Merge so I can save the score under some embedded data like var scoreString = "scoreVideo" + loopNum?
Thank you very much for reading! I understand it's a little complex.

icon

Best answer by ahmedA 17 March 2021, 20:41

View original

3 replies

Userlevel 7
Badge +21

Loop and merge has an embedded data called something like loop number or loop count (see the exact name in the piped text dropdown).
Just add that to the names of your embedded variables. Something like:
let loop_count = "{loop and merge count}";
Qualtrics.SurveyEngine.setEmbeddedData(loop_count+"condition", "Z");
Qualtrics.SurveyEngine.setEmbeddedData(loop_count+"scoreVideo", score);

You'll need to create these 20-30 embedded variables in the survey flow to download them.
Also, I don't see how you got to 4060?

Thanks ahmedA for your answer! That helped. The code I ended up with was:
var loop_count = parseInt("${lm://CurrentLoopNumber}");
var score = parseInt("${lm://Field/1}");
Qualtrics.SurveyEngine.setEmbeddedData("condition", "Amateur");
Qualtrics.SurveyEngine.setEmbeddedData("video" + loop_count, score);

I embed the variables "condition", "video1", "video2", and "video3" after consent. This works extremely well.
With regards to 4060, I calculated it doing n choose k which is given as n!/(k!(n-k)!). In this case of having say 30 videos to choose from and 3 videos chosen gives 30!/(3!(30-3)!) = 4060.

Badge

Thanks so much for this thread. I tried making this work with my survey, but unfortunately I'm not having much luck (my equivalent of video1, video2 and video3 remain blank at the end of the survey). I wondered if you (or someone else with experience) could share more about this:

  1. Are you using Survey Flow --> Set Embedded Data to create the initial video1, video2 etc. variables? Are you typing the variables with the "" or without (for example, writing "video1" as the embedded variable)?

  2. Where are you entering your JS code? I assume it's in the loop and merge block, at the very beginning of the block? Do you paste all the code in the Onload or OnReady block?

Any other ideas here would be super helpful. I've been looking at this survey for an hour to try and fix this, to no avail!

Leave a Reply