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.


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.

So, the issue with using CurrentLoopNumber is that your data will mixed up (i.e., _1 will refer to different images in each response). I you want save presentation order, I recommend saving it as a separate embedded field (e.g., image_order_1) 


@TomG 

Thank you for pointing this out. There may be a bit of confusion, let me rectify.
Suppose at first trial img9 is displayed along with two (radio button type) questions, and let I have answered Q1 as choice 1 and Q2 choice 1.
In embedded data with loop = "${lm://CurrentLoopNumber}", JavaScript will update embedded field as:
image_name_1 = img9
image_type_1 = True_9
ans_q1_1 = 1
ans_q2_1 = 1

But with loop = "${lm://Field/4}", JavaScript will save it as:
image_name_9 = img9
image_type_9 = True_9
ans_q1_9 = 1
ans_q2_9 = 1

Therefore, in exported data, I will see 1st presented image (i.e., img9) along with its answers (i.e., 1, 1) in 9th position rather than in 1st position. loop = "${lm://CurrentLoopNumber}" is a sequence of number starting from 1 which gives the benifits of updating embedded data from the 1st.

Many thanks for continuous discourse.
Have a lovely day. 


@TomG 

Thank you for pointing this out. There may be a bit of confusion, let me rectify.
Suppose at first trial img9 is displayed along with two (radio button type) questions, and let I have answered Q1 as choice 1 and Q2 choice 1.
In embedded data with loop = "${lm://CurrentLoopNumber}", JavaScript will update embedded field as:
image_name_1 = img9
image_type_1 = True_9
ans_q1_1 = 1
ans_q2_1 = 1

But with loop = "${lm://Field/4}", JavaScript will save it as:
image_name_9 = img9
image_type_9 = True_9
ans_q1_9 = 1
ans_q2_9 = 1

Therefore, in exported data, I will see 1st presented image (i.e., img9) along with its answers (i.e., 1, 1) in 9th position rather than in 1st position. loop = "${lm://CurrentLoopNumber}" is a sequence of number starting from 1 which gives the benifits of updating embedded data from the 1st.

Many thanks for continuous discourse.
Have a lovely day. 

Correct. My suggestion was to use the latter with one more field:

image_name_9 = img9
image_type_9 = True_9

image_order_9 = 1
ans_q1_9 = 1
ans_q2_9 = 1

The embedded fields will be in the order you define them in the survey flow, not in the order they are populated. Typically, one wants to know what respondents think of image 9 and having those answers in the same field makes analysis easier. You can use image_order_9 to determine if there is order bias.


Thank you. My point was to stick to the way I have defined embedded data fileds as there is no clue which image will be presented in 1st, 2nd, 3rd and so on. Anyway, it was lovely to having a discusion in resolving the issue, will come again if there are more. Best regards.