How can I use embedded data with loop and merge+javascript? | XM Community
Skip to main content
I am implementing jQuery datepicker with merge and loop. I have implemented it to my requirement for one loop. But it requires me to set up an embedded field called 'date' but since I want to loop through (a max. of thirty times), it obviously overwrites the date field. Is there a way to suffix the loop index into my javascript code so that it stores it in different date variables depending on the loop number? I used the code provided in this question and I think this is where I need to make a change:



Qualtrics.SurveyEngine.addOnPageSubmit(function()

{

Qualtrics.SurveyEngine.setEmbeddedData( 'date', document.getElementById('datepicker').value );

});







Thanks!
Yes, change it to:

```

Qualtrics.SurveyEngine.setEmbeddedData( "date${lm://CurrentLoopNumber}", document.getElementById("datepicker").value );

```

You'll have to add date1, date2, ..., dateX (where X is the maximum number of loops) as embedded data fields in your survey flow for them to be saved in the response data
Hi TomG,

Thanks, this is great. A quick follow up -how can I use this as a piped text in the loop and merge setting. I'd like to ask something like "How much did you workout on [insert piped text for selected date in that loop]"?



I tried this ' ${e://Field/date${lm://CurrentLoopNumber}} ' but it seems like incorrect syntax. Thanks!
> @JordanP said:

> Hi TomG,

> Thanks, this is great. A quick follow up -how can I use this as a piped text in the loop and merge setting. I'd like to ask something like "How much did you workout on [insert piped text for selected date in that loop]"?

>

> I tried this ' ${e://Field/date${lm://CurrentLoopNumber}} ' but it seems like incorrect syntax. Thanks!



You can’t nest pipes. If you need to pipe the value in each loop, you should attach the date picker to a Qualtrics text question, then pipe the answer to the question.

Leave a Reply