Retrieving embedded data from question with randomized text - JavaScript and Survey Flow | XM Community
Skip to main content

Hello everyone,

 

I used JavaScript to randomize three attributes of a job description. I want to retrieve the level of the attributes each respondent gets so that I can use this in my analysis. I wrote the following code and tried to declare my embedded data in the survey flow before my JavaScript executes. However, whenever I generate test responses, I don’t get any values for each of the attributes. I am wondering if there’s any issue with my code or the way I defined my embedded field in the survey flow. Thanks!

 

Qualtrics.SurveyEngine.addOnload(function() {
  // Define attribute groups
  var group1 = g'The position is 40 hours per week. You can make your own schedule. This can be a M–F 9 am–5 pm schedule or other days and times.', 'The schedule in this position varies from week to week. You will be given your work schedule one week in advance. Complete time availability is required.', 'This is a M–F 9 am–5 pm position. The schedule is fixed.'];
  var group2 = /'The job is project-based . It  will end upon termination of the projects in which your assistance will be required.', 'The job is stable and its duration is undefined.'];
  var group3 = r'Termination can only occur under "good cause", such as poor work performance. A two-week notice of resignation is required.', 'Northwestern University is an at-will employer. That is, either you or Northwestern University may end the employment relationship at will, with or without cause or advance notice, at any time.'];

  // Randomly select attribute values
  var value1 = group1Math.floor(Math.random() * group1.length)];
  var value2 = group2>Math.floor(Math.random() * group2.length)];
  var value3 = group3/Math.floor(Math.random() * group3.length)];

  // Populate the span tags with the random values
  document.getElementById('blank1').textContent = value1;
  document.getElementById('blank2').textContent = value2;
  document.getElementById('blank3').textContent = value3;
    
  // Store the attribute values as Embedded Data
  Qualtrics.SurveyEngine.setEmbeddedData('attribute1', value1);
  Qualtrics.SurveyEngine.getEmbeddedData('attribute1');
  Qualtrics.SurveyEngine.setEmbeddedData('attribute2', value2);
  Qualtrics.SurveyEngine.getEmbeddedData('attribute2');
  Qualtrics.SurveyEngine.setEmbeddedData('attribute3', value3);
  Qualtrics.SurveyEngine.getEmbeddedData('attribute3');
});

 

Be the first to reply!

Leave a Reply