Javascript and Embedded Data | XM Community
Skip to main content

The three questions below use display logic to identify an individual’s specific hobby.

 

A subsequent question (below) randomizes four conditions. The first condition (i.e., ${e://Field/__js_randomActivity}) should display a random unselected hobby.

 

I use the code below to identify an unselected hobby then assign it to an embedded data field, which should populate in the survey.

 

Qualtrics.SurveyEngine.addOnload(function()
{
        var allActivity = "Soccer", "Basketball", "Swimming", "Tennis", "Baseball", "Football, American", "Golf", "Dance", "Acting", "Singing", "Painting", "Writing", "Sewing"];

var participantActivity = "${q://QID3/ChoiceGroup/SelectedChoices}";
    
console.log("Participant Activity:", participantActivity);
    
var otherActivity = allActivity.filter(function(activity) {
        return activity !== participantActivity;
    });
    
console.log("Other Activity:", otherActivity);
    
var randomActivity = otherActivityaMath.floor(Math.random() * otherActivity.length)];
    
console.log("Random Activity:", randomActivity);
    
Qualtrics.SurveyEngine.setJSEmbeddedData('randomActivity', randomActivity);


});

 

The code executes correctly. As depicted in the following image, it identifies and assigns a value to the relevant variable (i.e., randomActivity).

 

Yet, as shown below, the embedded data field does not populate in the survey.

 

In the survey flow, I altered the position of the embedded data field , yet it remained unpopulated. I moved the Javascript to an earlier question, and the field remained unpopulated. I added about two dozen questions between the first and second block to allow processing time, but the relevant field remained unpopulated. I asked Qualtrics’ support about Javascript permissions on my account, and Javascript is enabled on my account.

 

What else could be causing the field to not populate in the survey, and how can I resolve the issue?

 

For reference, I present the survey flow from top to bottom.

 

 

 

Be the first to reply!

Leave a Reply