Connecting javascript, embedded data, and loop and merge block | XM Community
Question

Connecting javascript, embedded data, and loop and merge block

  • 28 May 2021
  • 1 reply
  • 40 views

I am trying to program a conjoint and best as I can tell have followed the steps on this guide: https://m-graham.com/resources/conjoint%20how-to.pdf . However, my tables for the conjoint choices are not populating, and I cannot see where it is breaking. Any suggestions would be greatly appreciated! Code for all steps is below.
Here is the javascript I used for randomization in an early question that every respondent sees (I did put this through Visual Studio and it didn't flag anything):
Qualtrics.SurveyEngine.addOnload(function()
{
response.setContentType("text/plain");
// Set number of choices ;
 var numChoice = 4;
// Vectors containing all attribute levels :
 var relidenomArray = [" Baptist", " Presbyterian ", " Methodist ", " Catholic "];
 var theoposArray = [" Evangelical ", " Mainstream "];
 var locationArray = [" Urban ", " Rural "];
 var stateArray = [" Georgia ", " New York "]; 
 var poliorientArray = [" Republican ", " Purple church ", " Democratic "];
 var ethcompArray = [" Predominanty white ", " Ethnically diverse ", " Predominantly Black "];

// 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 = array [i];
 array [i] = array [j];
 array [j] = temp ;
 }
 return array ;
 }

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

// Perform the randomization and save the result :
 for (i = 1; i <= numChoice ; i ++) {
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _relidenom1 ", shuffle_one ( relidenomArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _relidenom2 ", shuffle_one ( relidenomArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _theopos1 ", shuffle_one ( theoposArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _theopos2 ", shuffle_one ( theoposArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _location1 ", shuffle_one ( locationArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _location2 ", shuffle_one ( locationArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _state1 ", shuffle_one ( stateArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _state2 ", shuffle_one ( stateArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _poliorient1 ", shuffle_one ( poliorientArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _poliorient2 ", shuffle_one ( poliorientArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _ethcomp1 ", shuffle_one ( ethcompArray ));
 Qualtrics . SurveyEngine . setEmbeddedData (" choice "+i+" _ethcomp2 ", shuffle_one ( ethcompArray ));
 }
 });

Here is a screenshot example of the embedded data in the survey flow (I've checked they all match the syntax choicei_variable1 and 2 for choices 1-4, and this comes before the javascript):
surveyflowexample.PNG
In the Loop and Merge block, I have this for the Fields, repeated for each attribute:
image.png
Finally, I call the Fields into the survey questions using ${lm://Field1} up to Field 12. I do this four times for a total of four choice sets with two profiles each.


1 reply

Update: I tested out populating the Loop and Merge table with strings and calling them into a blank question in the block using ${lm://Field1}, and it still appears blank. Any ideas why that might be?

Leave a Reply