Loop and Marge with saving embedded data in a certain order | XM Community
Skip to main content

Hello,

 

I am displaying images (at the top of the page) and then two related questions (just below the image). Questions are radio button choices and they are always the same regardless of images (there are 16 images altogether randomly presented). This part is working fine with Loop and Marge (with three fields, Field-1: image link from library, Field-2: image_type, Filed-3: image_name)

 

I want to know: Which image was presented, type of image, answer choice selected for Q1, answer choice selected for Q2.

 

I have created embedded data (16 images x 4) 64 fields (it’s a messy way) but having difficulties in saving the data:

  1. Image name (Filed 3, working fine, I can save it with embedded data)
  2. Image type (Filed 2, working fine, I can save it with embedded data)
  3. Which answer was selected for the image for Question-1 (Not working, I can’t save it with embedded data)
  4. Which answer was selected for the image for Question-2(Not working, I can’t save it with embedded data)

 

I want the data (after exporting) to be look like this:

image_name_1, image_type_1, ans_q1_1,  ans_q2_1, image_name_2, image_type_2, ans_q1_2,  ans_q2_2, …, image_name_16, image_type_16, ans_q1_16,  ans_q2_16

img_10,                 good                     1,                     3,                  img_7,                    good                     2,                     5,    and so on

 

I will share the survey if you would like to, please let me know.

 

Note: I believe QID is the issue as it changes with prefix but not sure how to catch it, you may be the right person for help.

 

Your support would be highly appreciated.

 

Thank you.

Kind regards,

W

@wuaham,

Maybe you are making it more complicated than need be?  If the 16 images are 16 rows in your loop & merge setup and you randomize the loops, then loop 1, 2, 3, etc. for Q1 and Q2 in your data correspond to images in row2 1, 2, 3, etc. in your loop & merge setup.  You don’t really need embedded data.  


@TomG

Your point is right but the way data is being stored by Qualtrics requires a huge amount of work to clean up, I have to plough through data one after another to line up presented image and it’s corresponding answers as they are scattered all over (data row) and searching manually is a possibility of error.
I am updating embedded data with JavaScript for image name and type all working fine but updating answers (for Q1 and Q2) with JavaScript becomes an issue (it’s QID which I am unable to catch due to its prefix). I am now planning to write scripts (Python, MATLAB or R) to do the clean up work on the exported data and will see if anyone can come up with an answer we are not aware of. Many thanks for your reply. Best


You can make one of the loop and merge fields the row number (1, 2, 3, etc.). Let’s say field 4 since it seems you already have 1 through 3. Then JS for Q1:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var se = Qualtrics.SurveyEngine,
loop = "${lm://Field/4}",
type = "${lm://Field/2}",
name = "${lm://Field/3}";
se.setEmbeddedData("image_name_"+loop,name);
se.setEmbeddedData("image_type_"+loop,type);
se.setEmbeddedData("ans_q1_"+loop,this.getChoiceRecodeValue(this.getSelectedChoices().pop()));
});

Then for Q2:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var se = Qualtrics.SurveyEngine,
loop = "${lm://Field/4}";
se.setEmbeddedData("ans_q2_"+loop,this.getChoiceRecodeValue(this.getSelectedChoices().pop()));
});

 


Excellent, it works. Thank you.

Just a note: I used loop = "${lm://CurrentLoopNumber}" instead of Field 4 and in this way I also know the order of presentaion of the images. Your idea is also right if I do not want to know the oder of presentation.

Have a  great and take care.