Branch Logic based on embedded data | XM Community
Solved

Branch Logic based on embedded data

  • 20 August 2020
  • 7 replies
  • 379 views

Badge

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

icon

Best answer by rondev 21 August 2020, 12:28

View original

7 replies

Userlevel 6
Badge +28

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"

Userlevel 7
Badge +27

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

Badge

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}");
 
 
}
});

Userlevel 7
Badge +27

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

Badge

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

Userlevel 7
Badge +22

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

Badge

Thanks Rondev, this seems to be working now!

Leave a Reply