Read in embedded variables using a loop | XM Community
Solved

Read in embedded variables using a loop

  • 30 April 2021
  • 1 reply
  • 27 views

Userlevel 2
Badge

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?

icon

Best answer by ahmedA 10 May 2021, 01:24

View original

1 reply

Userlevel 7
Badge +21

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