Custom Java: Are var values stored across surveys? | XM Community
Skip to main content

Hi: I'm new here and new to Qualtrics.
I programmed two different surveys. Each has a conjoint that I programmed using Javascript (not the Qualtrics conjoint tool). The conjoints are the same but the values that variables take on are different. I changed them appropriately in the Javascript and ran many previews. All looked great.
Then I ran a pilot. The data for Survey 2 (programmed second) contains a mix of the values in the Java script for both Survey 1 and Survey 2.
How is this possible? Does Qualtrics store the values in Java variables across surveys? Still, Survey 1 data does not include values from Survey 2 vars.
Most importantly, is the fix just to rename vars across the surveys or might this require something else? Main study is set for this Monday morning.
Thanks for your advice.

Here's the relevant code. Apologies for not uploading it originally. I varied the values for partyArrayA, experienceArrayA, and bribeArrayA across the two surveys but not the var names. My question is how values specified in Survey 1 ended up in the data for Survey 2.

Qualtrics.SurveyEngine.addOnload(function (){
// Set number of choices;
var numChoice = 2;
// Vectors containing all attribute levels:
var partyArrayA = ["Frente de Todos", "Juntos por el Cambio"];
var experienceArrayA = ["0 años", "5 años", "10 años"];
var bribeArrayA = "No le ofrece dinero", "Le ofrece $2500 pesos", "Le ofrece $5000 pesos"];

// Fisher-Yates shuffle:
function shuffle(array){
for (var i = array.length - 1; i > 0; i--){
var j = Math.floor(Math.random() * (i + 1));
var temp = arrayri];
arrayri] = arrayrj];
arrayrj] = temp;
}
return array;
}

// Shuffle a vector, choose the first entry:
function shuffle_one(theArray){
var out = shuffle(theArray);
var out = outo0];
return(out)
};

// Perform the randomization and save the result:
for(i = 1; i <= numChoice; i++){
Qualtrics.SurveyEngine.setEmbeddedData("choice"+i+"_party1A", shuffle_one(partyArrayA));
Qualtrics.SurveyEngine.setEmbeddedData("choice"+i+"_party2A", shuffle_one(partyArrayA));
Qualtrics.SurveyEngine.setEmbeddedData("choice"+i+"_experience1A", shuffle_one(experienceArrayA));
Qualtrics.SurveyEngine.setEmbeddedData("choice"+i+"_experience2A", shuffle_one(experienceArrayA));
Qualtrics.SurveyEngine.setEmbeddedData("choice"+i+"_bribe1A", shuffle_one(bribeArrayA));
Qualtrics.SurveyEngine.setEmbeddedData("choice"+i+"_bribe2A", shuffle_one(bribeArrayA));
}
});

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});


Hey kengreene. I don't believe embeddedData can cross surveys like that. Each survey should be compartmentalized with it's own data. I just tested setEmbeddedData() in one survey, and then tried to use my variable in another survey in the same Qualtrics session in the same Chrome window and was not able to view/use it. Likewise, I copied your JS code into a survey and tried to use it's values in another survey in the same Chrome window thinking cookies might be at play here, but I couldn't use them in the second survey either.
Are there any other ways your surveys are related? Are you distributing them via personal links or a distribution list(ties back to directory contacts).

Lastly, if you're interested in exporting your surveys to qsf files, I could take a look further, but your scripting looks good. I think something else is at play. You could always try the renaming variables and see that changes the data, though your previews data look good, so I don't think that will help here...



Leave a Reply