Use a variable as parameter for the embedded data field in setEmbeddedData funtion | XM Community
Skip to main content
Solved

Use a variable as parameter for the embedded data field in setEmbeddedData funtion

  • March 26, 2020
  • 3 replies
  • 57 views

Rudi
QPN Level 3 ●●●
Forum|alt.badge.img+16
  • QPN Level 3 ●●●
Dear all, I am using the setEmbeddedData function within a loop. While I can use a variable for the value, it seems I can't use a variable for the embedded data field name. the parameters look like this at the moment. Qualtrics.SurveyEngine.setEmbeddedData([ArrayButtonNames[i]],WeekDays[ArrayWeekDaysOrder[i]]); I've also tried to add the quotes for the embedded data field name but this also hasn't worked. Does anyone have an idea if this is possible and how it works? Thanks a lot and best regards Rudi

Best answer by TomG

As long as the variable is a string you can use a JS variable as an embedded variable name. An issue with dynamically setting embedded variables is that they have to first be defined in the survey flow or they won't be saved in the response data. So, maybe they are getting set, but you aren't finding them if you look in the response data. Have you tried piping them into the subsequent question?

3 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • March 26, 2020
[ArrayButtonNames[i]] isn't a valid variable name. Do you mean ArrayButtonNames[i]?

Rudi
QPN Level 3 ●●●
Forum|alt.badge.img+16
  • Author
  • QPN Level 3 ●●●
  • March 26, 2020
Hi Tom, yes, thanks for your fast reply. You are correct. This went wrong when writing the question. In the script it was correctly: ArrayButtonNames[i] Best regards Rudi

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • March 26, 2020
As long as the variable is a string you can use a JS variable as an embedded variable name. An issue with dynamically setting embedded variables is that they have to first be defined in the survey flow or they won't be saved in the response data. So, maybe they are getting set, but you aren't finding them if you look in the response data. Have you tried piping them into the subsequent question?