Branch logic problem: different conditions that are true for all loops | XM Community
Skip to main content

Hi all,

I'm building a rather complex set of loop blocks and conditions to check whether survey participants meet the study requirements, but I'm getting stuck. See the following fictitious, but representative example. Suggestions on how to handle this dilemma are most welcome!

So say we're interested in the school system in the late 1900's and want to survey parents who had a child that graduated between 1990 and 2000. We want to include all parents with at least one child that satisfies one of the following conditions:

  • Graduated from primary school between 1990 and 2000
  • Graduated from secondary school between 1990 and 2000
  • Graduated from higher education between 1990 and 2000

We test these conditions with four questions. Questions 2-4 are in a loop block that is dependent on the answer to question 1 and loops for N children:

  1. How many children do you have?
  2. When did your Nth child graduate from primary school?
  3. When did your Nth child graduate from secondary school?
  4. When did your Nth child graduate from higher education?

Respondents have to fill in a year to questions 2-4 and are allowed to leave the question blank when the child has not (yet) graduated from this type of education.

Now we build a branch that redirects to an end screen for respondents that do not meet the requirements. The conditions for this branch should be met if parents have answered question 2 AND 3 AND 4 for each child with a number lower than 1990 OR higher than 2000 OR with a blank. However, when setting up the condition you can only specify one specific answer that should be true for all loops, instead of several options of which one is true for all loops.

To illustrate, these are the conditions as I’ve set them up now:

  • For each loop, 2 is smaller than 1990

OR

  • For each loop, 2 is greater than 2000

OR

  • For each loop, 2 is blank

I’ve stacked this condition 3 times: once for each question. The problem with this approach is that if a parent fills in 1989 for child A and 2001 for child B for question 2, this parent should meet the condition but does not. The condition is only met if all children are before 1990, or all children are after 2000, or all children are left blank.

A simple solution would be to reverse the condition, and redirect respondents to the rest of the survey when for any loop the answer to 2, 3, or 4 is within the range 1990-2000. However, then we have to put the entire questionnaire under this branch. As our questionnaire is very long and includes several other branches, this is not a viable solution.

I hope my problem is clear and anyone has some ideas on how to tackle this! I’ve been puzzling for quite a while now so I’m very happy with any sort of help 😊

I think the easiest solution is to add a bit of JS to set a qualify flag, then branch based on that. For example:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var val = parseInt(jQuery("#"+this.questionId+" .InputText").val());
if(!isNaN(val)) {
if(val>=1900 && val<=2000) Qualtrics.SurveyEngine.setEmbeddedData("qualify","1");
}
});

 


I think the easiest solution is to add a bit of JS to set a qualify flag, then branch based on that. For example:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var val = parseInt(jQuery("#"+this.questionId+" .InputText").val());
if(!isNaN(val)) {
if(val>=1900 && val<=2000) Qualtrics.SurveyEngine.setEmbeddedData("qualify","1");
}
});

 

Thanks a lot @TomG , worked like a charm!! 😎
For interested readers: I added the JS to all three (2-4) questions and added a branch logic that redirects all respondents that score 0 on embedded data “qualify” to the end screen. Note that I had to assign 0 for "qualify” to all respondents first.


Leave a Reply