So far, we've seen a Rule that compared the answers to two questions and generated an error message, and a Rule that checked the answer to a single question and conditionally displayed another question.  This section will teach you some powerful new operators:


  • The QRange and Section selectors, which can be used to perform an action on a range of questions or a section.
  • The .andQ operator, which lets your RuleZ perform actions if the answer to one question AND the answer to another question both fulfill your criteria.
  • The .orQ operator, which lets your RuleZ perform actions if EITHER the answer to one question OR the answer to another question fulfil your criteria.



We will use a new survey for these examples:





The QRange selector

The first Rule that we want to create, written in simple English, is:


If the shopper made a dine-in visit, display the questions about when they entered and left the store.


The RuleZ code looks like this:

ifQ(51)                     // If the Visit Type
.answered(2)                // is "Dine-in"
.appear(QRange(11, 21));    // Show the "time entered store", and "time left store" questions

The QRange operator specifies a range of questions to be displayed: all questions starting from the first question number through the last question number.



The .andQ operator

Next, let's ask the shopper what type of beverage they ordered, if they said that they ordered a beverage, let's ask what kind:


If the shopper ordered a beverage, ask what type of beverage they ordered


You know how to do this one!  The Rule is:

ifQ(61)            // If the "What did you order?" question
.answered(2)       // was answered "Beverage"
.appear(Q(71));    // show the "What type of beverage?" question

…and now, if the shopper ordered a beverage, and if it was the type of beverage that is supposed to be cold, ask if their beverage was cold:


If the shopper ordered a beverage, and the beverage was soda or a shake, ask if the beverage was cold.


For this, we need the .andQ operator.  The Rule looks like this:

ifQ(61)            // If the "What did you order?" question
.answered(2)       // was answered "Beverage"
.andQ(71)          // and the "What type of beverage" question
.answered(2,3)     // was answered "Soda" or "Shake"
.appear(Q(41));    // ask if the beverage was cold

 Once again, capitalization matters! If you write .andq instead of .andQ, your Rule won't work!



The .orQ and .andifQ operators

Now let's add another rule to show the Cleanliness sections…but ONLY if the shopper did a dine-in visit AND didn't visit during the lunch hour rush.  In simple English, this would be:


If the shopper made a dine-in visit, and the time was before 11:30 am or after 1 pm, show the Cleanliness questions

To write the Rule, we need two new operators, the .orQ operator and the .andifQ operator, and the Section selector.  We're also going to have to do some new comparisons to check the time values.


The first part is easy:

ifQ(51)         // If the Visit Type
.answered(2)    // is "Dine-in"


The next part of the Rule is the "and the time was before 11:30 am or after 1 pm" part.  Because we are checking two conditions, we will use .andifQ – we want to have the section appear if the visit is a dine-in visit AND IF the time is before 11:30 am OR after 1:00 pm. The RuleZ code for this is:

 .andifQ(11)           // and if the time entered
.lessThan(41400))      // is before 11:30 am
.orQ(11)               // or if the time entered
.greaterThan(46800)    // is after 1:00 pm


 Whoa, what's with the 41400 and 46800???


Those are the times. In RuleZ, the time of day is always written in seconds.  1:00 am would be 3600: 60 minutes times 60 seconds.  11:30 am is 11 hours and 30 minutes (11*60*60 + 30*60), or 41400 seconds, and 1:00 pm is 13 hours (13*60*60).


Finally, we need to display the questions – but this time, instead of displaying one question or a range of questions, we want to display a section. In RuleZ, this is:

.appear(Section(1));   // display the Cleanliness section


The section number comes from the Survey Admin page, as shown below:




Our final Rule looks like this:

ifQ(51)                 // If the Visit Type
.answered(2)            // is "Dine-in"
.andifQ(11)             // and if the time entered
.lessThan(41400)        // is before 11:30 am
.orQ(11)                // or if the time entered
.greaterThan(46800)     // is after 1:00 pm
.appear(Section(1));    // display the Cleanliness section


 Now let's test our three RuleZ and see if the survey does what we expect it to do.  To recap, our three RuleZ are:


  • If the shopper made a dine-in visit, display the questions about when they entered and left the store.
  • If the shopper ordered a beverage, and the beverage was soda or a shake, ask if the beverage was cold.
  • If the shopper made a dine-in visit, and the time was before 11:30 am or after 1 pm, show the Cleanliness questions


Let's see what happens in our test shop.  Testing the first Rule, we can see that the "time in" and "time out" questions are not displayed for a drive-thru shop:



…but they are for a dine-in shop.  The first Rule is good!



Next, let's make sure that the "Was your beverage cold?" question only shows if the shopper ordered a soda or shake.  We can see that the question doesn't show if the shopper ordered a meal and not a beverage:


…or if the shopper ordered coffee:


…but it IS displayed if the shopper ordered soda or a shake:



Finally, the most complicated rule: you want to show the cleanliness questions, but only if the visit is a dine-in visit, and only if the visit is before 11:30 am or after 1:00 pm.  With our test shop, we can see that the cleanliness questions don't show if the shop is a drive-thru shop:


Now, for a dine-in shop: let's verify that the questions ARE displayed if the time is before 11:30 am:


...OR after 1:00 pm:


…but that the section is NOT displayed if the time is between 11:30 am and 1:00 pm:



RuleZ and Grids

At this time, RuleZ does not play nicely with FML, the mechanisms that facilitate the appearance of Grids and the function of paging. It is not presently an aim of this project to bridge this gap. With the exception of Grids, RuleZ can functionally replicate some of the same features of FML.