How can I utilize variable embedded data field names in display logic? | XM Community
Skip to main content

I have a loop and merge block, and I would like certain questions to display based on the value of an embedded data field that CHANGES with every loop. Here is my code, which does not work:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var trial = "${lm://CurrentLoopNumber}" - 1;
var embData = "rating" + trial;
if (Qualtrics.SurveyEngine.getEmbeddedData(embData) == -1) var display = 5;
Qualtrics.SurveyEngine.setEmbeddedData( "display", display)
And then in my display logic for the question, I say to show question if embedded data field called "display" is equal to 5.
Basically, I've named my embedded data fields in a systematic way so that they can be differentially accessed on different loops, so I'm not sure why this isn't working. I also have very little javascript experience, so any help would be greatly appreciated!

My suggestion is to use console.log to write the data to the console and in every loop, check the value and try to debug
var trial = "${lm://CurrentLoopNumber}" - 1;
console.log("trial",trial);
var embData = "rating" + trial;
console.log("embData",embData);
if (Qualtrics.SurveyEngine.getEmbeddedData(embData) == -1) var display = 5;
console.log("display",display);
Qualtrics.SurveyEngine.setEmbeddedData( "display", display)
If you don't know what console is, here are some information:
Web ConsoleDebugging JavaScript


Leave a Reply