# Configuring Conditions

Conditions show or hide controlled questions based on the response a respondent provides to one or more controlling questions. Single and compound condition types are available. See <a href="/en/lr/912970/#universal-survey-block-parameters">Universal Survey Block Parameters</a> on the Understanding Survey Parameters page for more information on how to assign the conditions described below to a question or instruction block in your survey.

**Limitation:** You cannot apply a cross-question validation to question responses that are controlled by a condition.

The following parameters will be within an array of conditions at the highest level in the survey JSON. See the example below to see where the conditions array belongs: 

~~~ json
{
 "name": "Survey Name",
 "description": "Survey Description",
 "licenseText": "© License Text",
 "sections": [
   ...
 ],
 "conditions": [
   {
     "name": "condition1",
     ...
   }
 ],
 "scores" :
 [
   ...
 ]
}
~~~

## Configuration Parameters for Single Conditions

Single conditions are based on a specific response or range of responses to a question. A question controlled by a single condition is only displayed to respondents if the condition evaluates to true based on the controlling question.

<table>
  <thead>
    <tr>
      <th>Parameter</th>
      <th>JSON Code Example</th>
      <th>Description</th>
      <th>Requiredness</th>
    </tr>
  </thead>
  <tbody>
    <tr>
        <td>The name of the condition</td>
        <td><code>"name": "condition1"</code></td>
        <td>
            <ul>
                <li>The unique name of the condition.</li>
                <li>Condition names are referenced by the controlled question or when configuring compound conditions.</li>
            </ul>
        </td>
        <td>Required</td>
    </tr>
    <tr>
        <td>The type of the condition</td>
        <td><code>"type": "single"</code></td>
        <td>
            <ul>
                <li>The type of the condition.</li>
                <li>For single conditions, the type should be single.</li>
            </ul>
        </td>
        <td>Required</td>
    </tr>
    <tr>
        <td>The name of the question block</td>
        <td><code>"blockName": "q1"</code></td>
        <td>The name of the controlling question block being evaluated by the condition.</td>
        <td>Required</td>
    </tr>
    <tr>
        <td>The operation of the condition</td>
        <td>
          <ul>
            <li><code>"operation": "=="</code></li>
            <li><code>"operation": "<"</code></li>
            <li><code>"operation": "NOT_INCLUDES"</code></li>
          </ul>
        </td>
        <td><p>The operation used to compare the triggering response to the respondent's response. The following operations are supported for single conditions:</p>
            <ul>
                <li>== - The response is exactly equal to the value in the answer node.</li>
                <li>!= - The response is not equal to the value in the answer node.</li>
                <li>< - The response is less than the value in the answer node.</li>
                <li>> - The response is greater than the value in the answer node.</li>
                <li><= - The response is less than or exactly equal to the value in the answer node.</li>
                <li>>= - The response is greater than or exactly equal to the value in the answer node.</li>
                <li>INCLUDES - The response includes the value in the answer node. This operation can only be used for multiple-choice question types.</li>
                <li>NOT_INCLUDES - The response doesn't include the value in the answer node. This operation can only be used for multiple-choice question types.</li>
            </ul>
            <p>The following operations are supported for single conditions when the triggering response is an optional answer:</p>
            <ul>
              <li>== - The optional answer is exactly equal to the value in the optionalAnswer node.</li>
              <li>!= - The optional answer is not equal to the value in the optionalAnswer node.</li>
            </ul>
        </td>
        <td>Required</td>
    </tr>
    <tr>
        <td>The answer</td>
        <td>
          <ul>
            <li><code>"answer": {...}</code></li>
            <li><code>"optionalAnswer": {...}</code></li>
          </ul>
        </td>
        <td>
        <ul>
          <li>The container for the response type and response value that the condition evaluates against.</li>
          <li>Options include:</li>
            <ul>
              <li>answer</li>
              <li>optionalAnswer</li>
            </ul>
        </ul>
        </td>
        <td>Required</td>
    </tr>
    <tr>
        <td colspan="4"><em>In the "answer" node:</em></td>
    </tr>
    <tr>
        <td>The type of answer</td>
        <td>
            <ul>
                <li><code>"type": "name"</code></li>
                <li><code>"type": "number"</code></li>
                <li><code>"type": "static"</code></li>
            </ul>
        </td>
        <td><p>The type of response value that the condition evaluates against. The type must match the controlling question's type and be consistent with the operation of the condition.</p>
            <table>
                <thead>
                    <tr>
                        <th>Type</th>
                        <th>Controlling Question Type</th>
                        <th>Operations</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>name</td>
                        <td>singleChoice, multipleChoice</td>
                        <td>singleChoice: ==, !=<br><br>
                            multipleChoice: INCLUDES, NOT_INCLUDES
                        </td>
                    </tr>
                    <tr>
                        <td>number</td>
                        <td>visualScale, numberScale, numberEntry</td>
                        <td>==, !=, <, <=, >, >=</td>
                    </tr>
                    <tr>
                      <td>static</td>
                      <td>date, time, dateTime</td>
                      <td>==, !=, <, <=, >, >=</td>
                    </tr>
                </tbody>
            </table>
            <div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>: Conditions for textEntry question types aren’t supported unless the condition is referencing an optional answer.</p>
    </div>
  </div>
</div>


            <div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>: Conditions for numberEntry only support number entry questions with a single answer, not those with multiple answers (e.g. Enter your height in feet and inches).</p>
    </div>
  </div>
</div>


        </td>
        <td>Required</td>
    </tr>
    <tr>
        <td>The triggering value of a name type answer</td>
        <td><code>"name": "1"</code></td>
        <td>The condition uses the operation (==, !=, INCLUDES, NOT_INCLUDES) to evaluate the respondent's response against this value.</td>
        <td>Required if type is name</td>
    </tr>
    <tr>
        <td>The triggering value of a number type answer</td>
        <td><code>"number": "10"</code></td>
        <td>The condition uses the operation (==, !=, <, >, <=, >=) to evaluate the respondent's response against this value.</td>
        <td>Required if type is number</td>
    </tr>
    <tr>
        <td>The triggering value of a static type answer</td>
        <td>
          <ul>
            <li><code>"value": "13:50"</code></li>
            <li><code>"value": "2022-12-02"</code></li>
            <li><code>"value": "2022-12-02T13:50"</code></li>
          </ul>
        </td>
        <td>
          <ul>
            <li>The condition uses the operation (==, !=, ==, !=, <, <=, >, >=) to evaluate the respondent's response against this value.</li>
            <li>The value must be in the format YYYY-MM-DD, HH:MM, or YYYY-MM-DDTHH:MM and correspond to the type of the block referenced in the blockName.</li>
          </ul>
        </td>
        <td>Required if type is static</td>
      </tr>
    <tr>
      <td colspan="4"><em>In the "optionalAnswer" node:</em></td>
    </tr>
    <tr>
      <td>The name of a triggering optional answer</td>
      <td><code>"name": "q1-notapplicable"</code></td>
      <td>The condition uses the operation (==, !=) to evaluate the respondent's response against this value.</td>
      <td>Required</td>
    </tr>
  </tbody>
</table>

### Example Single Condition JSON Configuration

The following JSON snippet illustrates the single condition parameters described above. The configuration below is not reviewed or licensed for use in collections.

~~~ json
"conditions": [
  {
    "name": "condition1",
    "type": "single",
    "blockName": "q1",
    "operation": "<=",
    "answer": {
      "type": "number",
      "number": "20",
    }
  },
  {
    "name": "condition2",
    "type": "single",
    "blockName": "q2",
    "operation": "==",
    "answer": {
      "type": "name",
      "name": "1",
    }
  }
{
    "name": "condition3",
    "type": "single",
    "blockName": "q3",
    "operation": "NOT_INCLUDES",
    "answer": {
      "type": "name",
      "name": "q1-1",
    }
  }
{
    "name": "condition4",
    "type": "single",
    "blockName": "q4",
    "operation": ">",
    "answer": {
      "type": "static",
      "value": "13:50",
    }
  }
{
    "name": "condition-optional",
    "type": "single",
    "blockName": "q5",
    "operation": "==",
    "optionalAnswer": {
      "name": "q1-notapplicable"
    }
  }
]
~~~

## Configuration Parameters for Compound Conditions

Compound conditions combine two or more conditions using an operation.

**Limitation:** Compound conditions can only contain conditions referencing blocks in the same survey part.

<table>
  <thead>
    <tr>
      <th>Parameter</th>
      <th>JSON Code Example</th>
      <th>Description</th>
      <th>Requiredness</th>
    </tr>
  </thead>
  <tbody>
    <tr>
        <td>The name of the condition</td>
        <td><code>"name": "condition3"</code></td>
        <td>
            <ul>
                <li>The unique name of the condition.</li>
                <li>Condition names are referenced by the controlled question or when configuring compound conditions.</li>
            </ul>
        </td>
        <td>Required</td>
    </tr>
    <tr>
        <td>The type of the condition</td>
        <td><code>"type": "compound"</code></td>
        <td>
            <ul>
                <li>The type of the condition.</li>
                <li>For compound conditions, the type should be compound.</li>
            </ul>
        </td>
        <td>Required</td>
    </tr>
    <tr>
        <td>The operation of the condition</td>
        <td><code>"operation": "AND"</code></td>
        <td><p>The operation that connects the conditions within this compound condition. The following operations are supported for compound conditions:</p>
            <ul>
                <li>AND - All conditions within this compound condition must be met to display the question.</li>
                <li>OR - Any condition within this compound condition must be met to display the question.</li>
            </ul>
        </td>
        <td>Required</td>
    </tr>
    <tr>
        <td>The conditions being compounded</td>
        <td><code>conditions": ["condition1", <br> "condition2"]</code></td>
        <td>The single or compound conditions that are being evaluated in the compound condition.</td>
        <td>Required</td>
    </tr>
  </tbody>
</table>

### Example Compound Condition JSON Configuration

The following JSON snippet illustrates the compound condition parameters. The configuration is not reviewed or licensed for use in survey collections.

~~~ json
"conditions': [
  {
      "name": "condition6",
      "type": "compound",
       "operation": "OR",
       "conditions": ["condition1", "condition2"]
  },
  {
      "name": "condition7",
      "type": "compound",
       "operation": "AND",
       "conditions": ["condition3", "condition4"]
  }
]
~~~