Setting Embedded Data via Javascript | XM Community
Skip to main content

Hi All,
I am running into an issue with Setting Embedded Data via Javascript and then using it in branches & display logic.
In Q1, I am randomly assigning participants into control or intervention groups using the following code:
************
Qualtrics.SurveyEngine.addOnload(function()
{
var rnd = Math.random();
if (rnd >.5)
{
Qualtrics.SurveyEngine.setEmbeddedData("InterventionStatus","Intervention");
}
else
{
Qualtrics.SurveyEngine.setEmbeddedData("InterventionStatus","Control");
}
});
************
Based on the answer to the question of Q2, I am assigning a value to embedded data code:
************
Qualtrics.SurveyEngine.addOnUnload(function()
{
if (this.getChoiceRecodeValue(this.getSelectedChoices()) == 0) {
var age = 1;
}
else {
var age = 0;
}
Qualtrics.SurveyEngine.setEmbeddedData("U18",age);
});
************
The issue I am having is that after this question is done, I am branching to one of four different survey questions. Instead of branching, it is going directly to the end of the survey and skipping all branches. If I add a question on a new page AFTER the javascript questions and BEFORE the branching, it works. Any idea why this is happening?

Change

addonUnload 
to
addOnPageSubmit
.
You can look at the details here


Leave a Reply