Search code examples
javascriptoperator-precedenceoverwriteembeddingqualtrics

Prevent JavaScript from overwriting identical embedded data in Qualtrics


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?


Solution

  • 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
    });