Conditions in DOC GEN Documents

SKIP AHEAD TO 
Why would you add conditions to your DOC GEN document?
How do you add conditions to your DOC GEN document?
How can you add conditions more easily inside DOC GEN documents?
What are the different conditions you can have inside a DOC GEN document?
Can you also add dynamic lists inside DOC GEN documents?

 

Why would you add conditions to your DOC GEN document?

You can design your DOC GEN document to conditionally display sections of text or variables based on the end user inputs inside your Checkbox App. Similar to referencing variables inside a DOC GEN document, this allows bespoke documents (agreements, contracts etc) to be generated through Checkbox.

 

How do you add conditions to your DOC GEN document?

To start a conditional section inside your DOC GEN document, use the following syntax: {{# Expression}} 

  • The '#' can be treated as an 'IF'
  • The Expression is the condition that needs to be true for the subsequent text to appear 

To end a conditional section, type {{/}} 

Between the start and end of the condition syntax, you can add text and variables which you wish to display if the condition is met.

For example: 

{{#Account_Balance < 0}} Your account balance is below zero {{/}} 

In the above example, if the end user input for Account_Balance variable is below 0, the condition will be true and therefore display "Your account balance is below zero" inside the DOC GEN document once generated through the Checkbox App. If the condition is not met, neither the condition syntax nor the text will not be displayed (provided that there are no syntax errors).

 

How can you add conditions more easily inside DOC GEN documents?

You can use the Checkbox Word Add-in to connect your Checkbox Apps to Microsoft Word (DOC GEN document) to easily insert the conditions syntax inside your Word document. Condition syntaxes inserted via the Checkbox Word Add-in are highlighted in green to easily indicate the start and end of a condition inside the document. Inserting conditions this way also reduces the chance of any syntax errors created by manually typing the condition syntax.

The Checkbox Word Add-in also has an in-built validator which helps identify any syntax errors in the document, allowing you to upload an error-free DOC GEN document to your App.`

 

What are the different conditions you can have inside a DOC GEN document?

There are many different conditions you can add to your syntax based on Conditions and Operators to display text and variables conditionally. See below for the different combinations that are possible and their examples.

  1. If you only want to display a portion of the text if condition 1 AND condition 2 are satisfied, type && between the two conditions. 

    For example:
     
    {{#Account_Balance < 0 && Account_Name == "James"}}  
    Your account balance is below zero and your name is James {{/}} 

    Note:
    In Checkbox, if you would like to check if a variable like 'Account_Name' is equal to something else, you use the double equals ('==') notation displayed above. 

  2. If you would like to display a message if condition 1 OR condition 2 are satisfied, type || between the two conditions.

    For example: 
    {{#Account_Balance < 0 || Account_Balance > 100}} 
    Your account balance is either below zero or above 100 {{/}}

  3. To make more complex requirements for displaying a particular message, string together as many AND or OR statements you deem appropriate in the same way as displayed above. 

    For example: 
    {{#(Account_Balance < 0 || Account_Balance > 100) &&  
    (Account Name == "James")}} 
    James, your account balance is either below zero or above 100 {{/}} 

    Note:
     The brackets ( ) were placed around the first two statements because it indicates that if both of them are false or the Account name is not James, then the message will not display.  

    If the brackets were placed in a different area, as shown in the example below, then the meaning would be more like the following: 

    {{#Account_Balance < 0 || (Account_Balance > 100 &&  
    Account Name == "James")}} 

    Either your account balance is below zero or your name is  
    James and your account balance is above 100 {{/}} 

  4. You can also create conditions that will be met if a text variable is not null. That is, if there is any user input for the text input field, the condition will be met. 

    The syntax for this is as follows:
Format Example 
{{#!!TXT#}} display text {{/}}  {{#!!TXT12}} The text variable is not null {{/}} 


Note:
If the text variable name has been changed, please refer to the respective variable name. 

 

Can you also add dynamic lists inside DOC GEN documents?

Yes, lists can also be displayed conditionally based on the end user's answers provided in an Assessment.

Let's take an example of checking which fruits the grocery store stocks in a list of checkboxes.

 If CBX1 == "TRUE" this means the store has apples 

 If CBX2 == "TRUE" this means the store has oranges 

If CBX3 == "TRUE" this means the store has pears 

You can present this in the document template as: 

This grocery store stocks: 
     {{#CBX1 == "TRUE"}} 
     1. apples {{/}} 
     {{#CBX2 == "TRUE"}} 
     2. oranges {{/}} 
     {{#CBX3 == "TRUE"}} 
     3. pears {{/}} 

Note: It is best practice to close the conditional section with {{/}} as the same line as the text as shown above to avoid any awkward spaces between each list item.

i.e. DO NOT do the following:

{{#CBX1 == "TRUE"}} 
     1. apples
{{/}}

During the assessment, if the user only checks CBX 1 and CBX 3, the Document will display: 

This grocery store stocks: 

  1. apples
  2. pears

As you can see, while 'pears' is the third entry in your template, it appears as the second entry on your Document as the condition for oranges wasn't met. 

Note: To ensure the word document retains the correct order in the numbered list, after you type: 

{{#CBX1 == "TRUE"}} 

  1. apple{{/}}
      

Press Shift + Enter. This will add a line under '1.' where you can then type the next condition. After the next condition, simply press Enter and '2.' will appear. 

 

Related Articles: