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

Branch Logic based on embedded data

  • August 20, 2020
  • 7 replies
  • 659 views

Forum|alt.badge.img

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

Best answer by rondev

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

7 replies

Appzk
QPN Level 5 ●●●●●
Forum|alt.badge.img+34
  • QPN Level 5 ●●●●●
  • August 20, 2020

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"


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • August 20, 2020

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


Forum|alt.badge.img
  • Author
  • August 20, 2020

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


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • August 20, 2020

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


Forum|alt.badge.img
  • Author
  • August 21, 2020

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


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • Answer
  • August 21, 2020

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


Forum|alt.badge.img
  • Author
  • August 21, 2020

Thanks Rondev, this seems to be working now!