Javascript custom Embedded Data not displaying as piped text | XM Community
Skip to main content

Hi! I’m trying to randomize my question text using Javascript.

 

The survey flow looks like this:

AD_4nXf2C_EDfFei6oaosGRCEt3LGzVV8LfHUG2WaSndo0YRKOQkviEI9BoGEEFkuReIhnGcfyMZnQHzr1DZV04nOUuPoGMLw5tvtUE1piESwefnqwnmuJdnGsmqVqkgAst61p0F-e91XTYhMATmC5UVs3CYZWs0?key=S0riyYyDSlQURiD3smRFSw

I have an embedded data called Identifier, and I put it above the question block in my survey flow. 

 

Question 1 (Welcome) has the following Javascript: 


Qualtrics.SurveyEngine.addOnload(function() {

    function generateIdentifier() {

        var identifiers = v"Asian", "African", "European"];

        var randIndex = Math.floor(Math.random() * identifiers.length);

        return identifiersrandIndex];

    }

 

    var identifier = generateIdentifier();

    Qualtrics.SurveyEngine.setEmbeddedData('Identifier', identifier);

});

 

Question 2 (in a separate block) uses the following piped text:

${e://Field/Identifier} Golden Fab Tree


However, nothing displays in the question piped text when I preview. What might be the problem?

Are you using the simple theme?


Hi @disik 

place your code in addOnReady instead of addOnload: 

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

For me the same setup as yours works this way: 

Best
Christian


Leave a Reply