Online Survey Tutorials

SurveyGizmo Tutorials and Help Documentation

Tutorial: Advanced Rule Writing

Try the new Advanced Rule Creator

Throughout SurveyGizmo there are Advanced Rules for performing a specific task, such as showing a page only when a particular set of circumstances is true. Advanced rule writing is best used for setting up rules that are based on answers from more than one question on a previous page of the survey. With a few exceptions, these rules are available for Pro and Enterprise customers only. The Browser Redirect action is available at all account levels.

You will find large essay boxes for advanced rule writing in the following locations:

  • Page Options & Logic – Advanced Show-When Rule
  • Question Advanced Edit: Advanced Piping and Logic – Hide When Rule
  • Question Advanced Edit: Advanced Piping and Logic – Require When Rule
  • Action: HTTP Form Post – Adv. Submit Rule (Enterprise only)
  • Action: Get Web Content – Adv. Submit Rule (Enterprise only)
  • Action: Send Email – Do Not Send When Rule (Personal and above)
  • Action: Redirect Browser – Redirect Suppression Rule (All account levels)
  • Action: ExactTarget – Don’t Run When (Enterprise only)
  • Action: SalesForce – Action Run-When Rule (Enterprise only)

These rules can be written to evaluate the reporting values from the following question types:

  • Text Field
  • Radio Buttons
  • Drop-down menu
  • Image Choice (single select)

Checkbox questions cannot be evaluated by advanced rule writing

An example of an advanced rule looks something like this:

( [%%12:question%%] > 32 AND [%%13:question2%%] < 32 ) OR '[%%2:gender%%]' == 'Male'

Key:

[%%12:question%%]

is a Merge Code

>

is an Operator

32

is a Numeric Value

‘[%%2:gender%%]‘

is a Merge Code

==

is an Operator

‘Male’

is a String Value

Syntax – Merge Codes

The first element of the rule is the merge code for the question (e.g. [%%12:question%%] ), which represents the Reporting Value for that question that is stored by SurveyGizmo for the survey (a.k.a. the respondent’s answer).

To find the merge code for the questions in your rule, there are two options: Use the Simple Piping Wizard or find the Question ID and manually create the merge code.

  1. Use the Simple Piping Wizard
    • Go to a question that is after the question you wish to evaluate as part of the rule and click the Advanced Edit icon (the little notebook on the left side of the question). When the question opens up, on the right side of the Question Title box you will see a smaller box that includes the Simple Piping Wizard. Click the link at the bottom of that box that is labeled ‘Select a Variable’. A drop-down box will appear. Select the question from the list and a merge code will appear under the box. Copy that merge code and add it to your rule.
  2. Create the Merge Code manually
    • Go to the specific question which you wish to evaluate in the rule and click the Advanced Edit icon (the little notebook on the left side of the question). When the question opens up, on the right side of the Question Title box you will see a smaller box which includes the Question ID. To create the merge, use the format:
      [%%xx:%%]
      xx represents the question ID found in the question editor, e.g. [%%23:%%]
      To clarify, the code is a left square bracket ( [ ), two percentage signs ( %% ), the question ID, a colon ( : ), two percentage signs ( %% ), and a right square bracket ( ] ).

Do NOT You can now use the query string merge codes [%%GET_xx] within advanced rule writing as well as Email Invitation Merge Codes. You must store these values in a Hidden Value action on a previous page then write an advanced rule using the Hidden Value field merge code.

Syntax – The Operator

The operator is the symbol that compares the Merge Code (left side) with the provided value (right side). The following operators are available and provide the following evaluation:

  • == : Equal to
  • != : Not Equal to
  • > : Greater than
  • < : Less than
  • >= : Greater than or equal to
  • <= : Less than or equal to

As a reminder, the rule is designed to find whether the evaluated rule is TRUE or FALSE, so if your rule is to Show When, a rule that uses != (Not Equal to) will Show the page When the Merge Code is Not Equal to the Value.

Example:

'[%%13:%%]' != 'two'

Also, please note that if you accidentally use a single equals sign ( = ) rather than a double equals ( == ), it will not work properly. Be careful about forgetting the second equals sign!

Numeric Values (numbers) vs String Values (words)

When evaluating an operator, if using greater than, less than, greater than or equal to, or less than or equal to, you are evaluating the value numerically. In this situation, it is critical that the source question that the Merge Code represents has only numeric Reporting Values. See the note at the bottom of this tutorial regarding Text Field question types and this issue.

If using equal to or not equal to, you are evaluating an exact value and regardless of if the value is a number, it needs to be evaluated as a string to work properly. Examples:

'[%%13:%%]' != '2'
'[%%13:%%]' != 'two'

Notice the use of single quotation marks surrounding both the Merge Code and the Value. This signifies that it should be evaluated as a string. Failure to do this correctly when the values are non-numeric will generate an error when the survey progresses past the first page!

Finally, be advised that the evaluation of the value is an exact match, which includes capitalization. ‘Bob’ and ‘bob’ are not the same thing, you want to match the Reporting Values (represented by the Merge Code) exactly!

Advanced Rule Checker

Multiple evaluations – AND, OR, and Parenthesis

The power of advanced rule writing is to combine multiple questions and values into a single rule, such as making sure that question 1 is yes and question 2 is no. In this situation, you would combine two Merge Code – Operator – Value evaluations together by the word AND:

'[%%9:%%]' == 'yes' AND '[%%10:%%]' == 'no'

If you wished to have the rule be true only if one or the other evaluation is true, you would use the word OR:

'[%%9:%%]' == 'yes' OR '[%%10:%%]' == 'no'

Finally, if you wish to evaluate one set of evaluations first before evaluating against another evaluation (or set of evaluations), you would surround the set by parenthesis, just like basic mathematics:

('[%%9:%%]' == 'yes' AND '[%%10:%%]' == 'no') OR '[%%29:%%]' == 'poor'

It is important to note that the following is incorrect:

NOT VALID:

'[%%9:%%]' == 'yes' OR 'no' OR 'poor'

Caveats – Text Fields and Numeric Evaluation

If you are using the Merge code of an open textbox question and wish to evaluate it as a number, there are extra precautions that should be put in place to ensure that the user’s input is a number, otherwise a rule error will occur, breaking the survey functionality for the respondent.

The most basic requirement is to edit the text field question and select ‘Auto-Format as Whole Number’. This will force only numeric values as responses to that field.

However, if you wish to provide more feedback to the user as to why you are not allowing them to enter in a non-numeric value, you can use Validation (near the bottom of the question editor). In the Validation section, you can display a custom message for the respondent if they violate the validation rule, such as “Must be a number.” For the Actual RegEx Pattern, you can use one of the following:

  • ^\d*$
    • Zero or more digits (0-9), no spaces, punctuation, etc.
  • ^\d+$
    • One or more digits (0-9), no spaces, punctuation, etc.

Finally, if using the Validation, the question should also be Required.

If you have any further questions, please use our community forums.