Iterate over the fields of Loop and Merge | XM Community
Skip to main content

Hello, I am somewhat new to Qualtrics and JavaScript. I have been trying to create a "for loop" to iterate over the fields in Loop and Merge and form a string with them. I am using a "for loop" because in the questions I have use a different number of fields.
I can get the information in the loop and merge fields if I do it manually like below.

var sentence = "${lm://Field/1}" + " " + "${lm://Field/2}" + " " + .... + "${lm://Field/10}";
alert('Original sentence ---> ' + sentence);

However, I want to do it with a "for loop" to iterate over the value saved in each field by accessing it by their number. Is this possible? I have been trying different things but I can't figure out how to use variables within template strings in Qualtrics.

var sentence = "";
for(i=0; i<10; i++)
{
var words = "${lm://Field/" + (i+1).toString() +"}";
sentence = sentence + " " + words;
}
alert('Original sentence ---> ' + sentence);

Any ides?
Miguel Santin

Could you share a screenshot of your LM setup?


ahmedA Sure, here it is.
Screenshot 2021-09-25 at 23.14.40.png


Leave a Reply