Set embedded data to count number of completed loops | XM Community
Skip to main content

Hi Qualtrics Community,
Currently, I'm using JavaScript with display logic to automatically advance blocks after 10 seconds spent on a Loop & Merge question.
I'm using the following code:
Qualtrics.SurveyEngine.addOnReady(function()

{

/*Place your JavaScript here to run when the page is fully displayed*/

var start = parseInt('${e://Field/start_time0}');

var end = parseInt('${e://Field/Q_TotalDuration}');

var elapsed0 = end - start;

Qualtrics.SurveyEngine.setEmbeddedData('elapsed0', elapsed0);

if(elapsed0 > 10) Qualtrics.SurveyEngine.setEmbeddedData('timeout0', 1);



});
What I'd like to accomplish: I need to set an embedded data variable that counts the TOTAL number of loops completed during the 10 seconds.
I have way, WAY more rows in the Loop & Merge matrix than participants can complete in 10 seconds. Most people will finish 3-5 loops in the 10 seconds. I need to know (in an embedded data field) how many they did complete (so that, in the next block, I can say "You completed ${e://Field/r0_score} questions during those 10 seconds.").
I don't know JS but, FWIW, here's what I've tried based on Googling: I initialized an embedded data object

r0_score
= 0 before the key block. Then, in the JS above (in the second-to-last line) I tried adding `Qualtrics.SurveyEngine.setEmbeddedData('r0_score',r0_score++);` but this didn't work.
Can anyone help?

Thanks so much as always!

I was able to solve this problem after a bit more tinkering. I'm posting the solution below in case it's helpful for anyone else:
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var start = parseInt('${e://Field/start_time0}');
var end = parseInt('${e://Field/Q_TotalDuration}');
var score = parseInt('${e://Field/r0_score}');
score++;
var elapsed0 = end - start;
Qualtrics.SurveyEngine.setEmbeddedData('elapsed0', elapsed0);
Qualtrics.SurveyEngine.setEmbeddedData('r0_score', score);
if(elapsed0 > 30) Qualtrics.SurveyEngine.setEmbeddedData('timeout0', 1);

});


Leave a Reply