Unable to access embedded data included in Javascript when downloading dataset (bit of an amateur!) | XM Community
Skip to main content
Solved

Unable to access embedded data included in Javascript when downloading dataset (bit of an amateur!)

  • January 24, 2021
  • 4 replies
  • 150 views

Hello!
I have been trying to randomize the questions that participants are shown in my survey (conjoint study). I have been successful in doing so, but I also need to see what questions my participants are shown when analyzing data. I am using this link as a guide: https://github.com/leeper/conjoint-example
I have used the following JS code to embed the data in responses:
// Create list of variables to use when setting attributes
a_list = ["a1","a2","a3","a4","a5"]; 
b_list = ["b1","b2","b3","b4","b5"]; 

// set html values in conjoint table
for(i=0;i<5;i++){
  document.getElementById(a_list[i]).innerHTML = traits_a[i];
  document.getElementById(b_list[i]).innerHTML = traits_b[i];
}

// store values as embedded data fields
Qualtrics.SurveyEngine.setEmbeddedData('traits1a', traits_a.join("|"));
Qualtrics.SurveyEngine.setEmbeddedData('traits1b', traits_b.join("|"));

This is in accordance with the link above. Unfortunately, I am unsure how to access this data when downloading my dataset. Any information would be appreciated!

Best answer by ahmedA

This is a surprise that everyone comes across after using JS for a bit. Add a variable with the same name in the Survey Flow and you'll find it present in the results.

4 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • Answer
  • January 24, 2021

This is a surprise that everyone comes across after using JS for a bit. Add a variable with the same name in the Survey Flow and you'll find it present in the results.


  • Author
  • January 24, 2021

Amazing! Thank you so much for the help, it worked perfectly!


  • January 25, 2021

ahmedA
I've been up and down the support forums for an answer to this. I've done exactly what was suggested by adding a Set Embedded Data object above my first question.
age = 0
The first question is the default age question from the Qualtrics library with the following javascript code:
Qualtrics.SurveyEngine.addOnload(function()
{
 //Set years you would like to have available 
 var yearFirst = 1900; //min is 1900
 var yearLast = 2020; //max is 2020
 
 //This remains unchanged
 var qid=this.questionId;
 var mo=document.getElementsByName('QR~'+qid+'~1')[0];
 var day=document.getElementsByName('QR~'+qid+'~2')[0];
 var yr=document.getElementsByName('QR~'+qid+'~3')[0];
  
 var mos=mo.getElementsByTagName("option");
 var days=day.getElementsByTagName("option");
 var yrs=yr.getElementsByTagName("option");
 
 //hide impossibles
 for(i=13;i<=150;i++)
 {
  mo.removeChild(mos[13]);
 }
 for(i=32;i<=150;i++)
 {
  day.removeChild(days[32]);
 }
 var j = yearLast-1898;
 for(i=j;i<151;i++)
 {
  yr.removeChild(yrs[j]);
 }
  
 for(i=1;i<=yearFirst-1900;i++)
 {
  yr.removeChild(yrs[1]);
 }
  
 function fixer()
 {
  day.options[29].disabled=0;
  day.options[30].disabled=0;
  day.options[31].disabled=0; 
  if(mo.selectedIndex==2||mo.selectedIndex==4||mo.selectedIndex==6||mo.selectedIndex==9||mo.selectedIndex==11){
   day.options[31].disabled=1;
   if(day.selectedIndex==31){day.selectedIndex=30};
   if(mo.selectedIndex==2)
   {
    day.options[30].disabled=1;
    if(day.selectedIndex==30){day.selectedIndex=29};           
    if(parseInt(yr.options[yr.selectedIndex].innerHTML,10)%4!=0)
    {
     day.options[29].disabled=1;
     if(day.selectedIndex==29){day.selectedIndex=28}; 
    }
    else
    {
     day.options[29].disabled=0;
    }
   }
  }  
 }
 yr.onchange=function(){fixer();};
 mo.onchange=function(){fixer();};
});

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
  var age = moment().diff(moment(jQuery("#"+this.questionId+" .InputText").val()), 'years');
  Qualtrics.SurveyEngine.setEmbeddedData('age', age);
  if(age > 13 && age < 25) Qualtrics.SurveyEngine.setEmbeddedData('eligible', '1');
});
In a subsequent block, forcing the user to submit the age question, I'm simply attempting to print out the age embedded data in a Text / Graphic style question:
${e://Field/age}
The response I always get back is: 0
What am I missing here?


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • January 25, 2021

tnomi If you always get back a zero, it implies that your JS is not working. Could you please add a new question related to your issue with details such as what do you intend to do, your question type, the exact problem, any troubleshooting that you've already done, some screenshots/ links of the survey etc.
This will help others in your situation find the solutions.