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

Branch Logic based on embedded data

  • Aug 20, 2020 3:25 PM UTC
  • 7 replies
  • 749 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

View original

7 replies

Appzk
QPN Level 5 ●●●●●
Forum|alt.badge.img+34
  • QPN Level 5 ●●●●●
  • Aug 20, 2020 3:42 PM UTC

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 ●●●●●●●●
  • Aug 20, 2020 3:43 PM UTC

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
  • Aug 20, 2020 4:18 PM UTC

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 ●●●●●●●●
  • Aug 20, 2020 4:23 PM UTC

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
  • Aug 21, 2020 10:04 AM UTC

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
  • Aug 21, 2020 10:28 AM UTC

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


Forum|alt.badge.img
  • Author
  • Aug 21, 2020 10:34 AM UTC

Thanks Rondev, this seems to be working now!