Evaluating branch logic in JS | XM Community
Skip to main content
Solved

Evaluating branch logic in JS

  • June 28, 2021
  • 2 replies
  • 29 views

Hi,
As many others before us, we are struggling with inexact progress bars when there are a lot of optional blocks in a long survey, causing participants to drop out.
Is there a way to evaluate, in JS, if some particular branches in the survey flow will be taken or not (before they've been reached by the participant)? Ideally I don't want to hardcode the logic in the JS as this is error prone, but instead use the same logic as the existing survey flow.
Thanks in advance!

Best answer by Yarin

That doesn't sound like it will work since I need to know which blocks I will reach before Qualtrics has gotten there.
I ended up solving this by injecting generated Javascript (if ("${q://QID5/....}") { ... }) in the footer evaluating the survey flow of the survey at run-time. A bit cumbersome, but seems to work.

2 replies

pogi
Level 2 ●●
Forum|alt.badge.img+14
  • Level 2 ●●
  • June 28, 2021

You could use Embedded in your survey flow for each branch. Once set you can use subsequent branches and JS with the embedded data variables.


  • Author
  • Answer
  • June 30, 2021

That doesn't sound like it will work since I need to know which blocks I will reach before Qualtrics has gotten there.
I ended up solving this by injecting generated Javascript (if ("${q://QID5/....}") { ... }) in the footer evaluating the survey flow of the survey at run-time. A bit cumbersome, but seems to work.