Read in embedded variables using a loop | XM Community
Skip to main content

I have a set of embedded variables, q1_ans, q2_ans, q3_ans, ....
In one of my questions, I would like to read in all these vars one at a time as part of a loop:
Qualtrics.SurveyEngine.addOnload(function()
{
var i;

for (i = 1; i <= 2; i++) {
  let ans_q = "e://Field/q" + i + "_ans}"
  let ans = "${" + ans_q+ "}";
console.log(ans);
}
});


How can I read in embedded variables in a JS loop?

It won't be possible this way, you'll need to use the inbuilt Qualtric methods for this:
Qualtrics.SurveyEngine.addOnReady(function () {
    for (let i = 1; i < 4; i++) {
        let ans = Qualtrics.SurveyEngine.getEmbeddedData("q" + i + "_ans");
        console.log(ans);
    }
});


Leave a Reply