Add data to a embedded data field (Number Set) | XM Community
Skip to main content
Hello everyone,



I have a loop and merge block where I generate different images in the addOnReady function. Since the loop runs the same code, I have only one embedded data field, I called it 'userChoice1' and the code I used is:



`Qualtrics.SurveyEngine.addEmbeddedData('userChoice1', confirmFinal() );`



I want to record the variable 'userChoice1' in every single iteration of the loop, but I can only record the last one with this code. Can this embedded field be like a array where I can push in data on every loop? Thanks.



userChoice1 is also set as a "Number Set" type embedded data.



Thanks!
you can create multiple embedded variable and in javascript you can write if condition to check with iteration is currently running based on that you can set the embedded variables
> @Imran_Ansari said:

> you can create multiple embedded variable and in javascript you can write if condition to check with iteration is currently running based on that you can set the embedded variables



But if I do that then I need more than 100 variables.



And how do I know which iteration of the Loop and Merge am I in?
I was dealing with a similar problem. I have created one embedded field and at each iteration of Loop and merge I took it and concatenated my actual value to it and a separator.

If you want to use it again later in the questionnaire, you can split it using the `split` method easily. (Values are in the randomized order, not the original one if the loop is randomized)

My original resource is here.



Qualtrics.SurveyEngine.addOnPageSubmit(function()

{

var questionText = "${lm://Field/1}" + ";"; //Takes field1 from Loop and merge (replace it wit your value of choice1) and adds a semicolumn to it

var order = "${e://Field/efield}"+ questionText; //gets the old value of e. field and concatenates a new value to it

Qualtrics.SurveyEngine.setEmbeddedData("efield", order); //updates the e. field



});

Leave a Reply