Branch Logic based on embedded data | XM Community
Skip to main content

Hi All,
I have the following survey flow, were I record a person's willingness to pay from a slider (WTP_Subject) and generate a random number in the same range (WTP_Random).
I'd like to show different branches depending on some logic based on the values as pictured below, but can't seem to get it to work. The embedded data fields are saving, but for some reason the logic isn't working.
Any help would be greatly appreciated!
SurveyFlow.PNG

Is your survey entering the branch "Choice is equal to Accept".
I dont see any value set to embedded data "Choice" in the survey flow.
Is it set somewhere thru java script in the block "Intervention_2"


Where are you setting the values of WTP_Random and WTP_Subject? In WTP_1 JavaScript? If so, post your script.


Hi, “Choice” is set in intervention2 and that seems to work.

WTP_Random and WTP_Subject are set in WTP_1, please find the code below:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
 
});
 
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
 
});
 
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
 
});
 
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
if(type == "next")
{
Qualtrics.SurveyEngine.setEmbeddedData("WTP_Random",(Math.random() * (0.21 - 0.0) + 0.0).toFixed(2));
Qualtrics.SurveyEngine.setEmbeddedData("WTP_Subject", jQuery("#"+this.questionId+" .ResultsInput:eq(0)").val());
console.log("${e://Field/WTP_Random}");
console.log("${e://Field/WTP_Subject}");
 
 
}
});


Your WTP_Subject jQuery syntax is wrong. It should be:
Qualtrics.SurveyEngine.setEmbeddedData("WTP_Subject", jQuery("#"+this.questionId+" .ResultsInput").eq(0).val());


Hi Tom,
Thanks for your reply - unfortunately the logic still doesn't work. I've attached a .qsf of a dummy trial below - the full experiment is much larger and made up of multiples of these trials.
Many thanks, Chris
Slider_Proto.qsf


In branch logic, we pipe the text in the last text box:
image.png


Thanks Rondev, this seems to be working now!


Leave a Reply