1

I used JavaScript to assign the same embedded data name (QItem) to 5 survey items.

For example, QID1:

Qualtrics.SurveyEngine.addOnload(function()
{   
    var itemText = "${q://QID1/QuestionText}";
    Qualtrics.SurveyEngine.setEmbeddedData( 'QItem', itemText );

});

QID2:

Qualtrics.SurveyEngine.addOnload(function()
{   
    var itemText = "${q://QID2/QuestionText}";
    Qualtrics.SurveyEngine.setEmbeddedData( 'QItem', itemText );

});

...

I set the embedded data in the survey flow at the beginning of the survey so that it would be exported when I download the data.

The items are randomized. Because the embedded name is the same for all 5 items, it overwrites each time. Therefore, the embedded data that is saved/downloaded is the text of the last question that is presented.

How can I rewrite this so that the embedded data that is saved/downloaded is the text of the FIRST question that is presented instead of the last?

missgwolf
  • 356
  • 1
  • 11
  • if questions are in array then u can save the array[0], in your download. Or you can simply check if setEmbeddedData already has a value then do not set again. I am sure there may be a `getEmbeddedData` function as well. – pixlboy Jun 10 '22 at 06:53

1 Answers1

2

You can try something on similar lines.

Qualtrics.SurveyEngine.addOnload(function()
{   
    var itemText = "${q://QID1/QuestionText}";
    if(!Qualtrics.SurveyEngine.getEmbeddedData('QItem')){
       Qualtrics.SurveyEngine.setEmbeddedData( 'QItem', itemText );
    }
    // only set the value if QItem is not set
});
pixlboy
  • 1,452
  • 13
  • 30
  • Worked perfectly. Thank you! If I've already collected some data, is it possible to change the JavaScript now and retroactively capture this information, or can I only apply this to new data moving forward? – missgwolf Jun 10 '22 at 07:09
  • 1
    Moving forward this will be applied obviously but if you have already collected some and do not want it, you may need to manually remove it from wherever u save. It could be DB clear, cache clear, file delete etc. If you can figure out what questions you need out of data you have saved, you can remove with some logic. May need to look at the structure. – pixlboy Jun 10 '22 at 07:12
  • Ah, okay. There is other information in this dataset that is important, so I can't delete it. I can still figure out which item was displayed first in that dataset without the updated JavaScript, but it will require a lot of coding (`R`) which I was hoping to avoid. – missgwolf Jun 10 '22 at 07:16
  • 1
    perhaps if u have logs u can maybe figure out which items went first in a set of 5 (say) – pixlboy Jun 10 '22 at 07:40