2017

Download for FREE

Tutorial - Using Conditional Text in Document Automation

This article offers advanced Microsoft Word (2010-2013) techniques for creating a Document Automation template with conditional fields that can determine when certain pieces of information should be pulled into your document and what information should be displayed. 

Important Note: Due to the order in which MS Word updates fields, templates with conditional statements work best when generating PDF documents with Document Automation.  If you want to use your conditional templates to generate MS Word documents, please follow the troubleshooting steps HERE.

If you are not familiar with Document Automation, please see the following support articles:

Document Automation: Uploading Templates and Generating Documents
Document Automation: Creating a Template

Contents

Understanding Conditional Statements
     What is a Conditional Statement
     Expressions
     Operator
     TrueText and FalseText
     Putting it all Together
Adding Conditional Fields to a Word Template
     Limitations and Syntax
Tips and Examples of Useful Conditional Statements
     Using Clio Checkboxes to Determine what is Displayed
     Using Clio Picklists to Determine what is Displayed
     Nesting Conditional Statements (Multiple Conditions)
     Adding Line Breaks to TrueText and FalseText
Troubleshooting Document Generation in MS Word
Advanced Document Automation Webinar

Understanding Conditional Statements in MS Word

What is a Conditional Statement?

In the most basic language, a conditional statement says that: if some condition is applicable, then do something. 

Conditional statements follow the general format: IF this THEN that or ELSE some other thing. For example:

  • IF the trust balance is 0, THEN display a message asking for another prepayment, ELSE display a thank you message
  • IF custom_field_1 is true, THEN display custom_field_2, ELSE display custom_field_3

In MS Word, the conditional statement format looks like this:

IF Expression1 Operator Expression2 "TrueText" "FalseText"

Expressions

Expressions are something with a value. In the example of Document Automation, a merge field tag can be an expression. A conditional statement has 2 Expressions, or values, that are compared in order to determine what information is displayed.

Note that Expressions (or merge field tags) that have a value that is in plain text need to be surrounded by quotation marks; but Expressions that have a numeric value should not be surrounded by quotation marks.

To indicate that a value is empty (specifically for the second Expression), use 2 quotation marks with nothing between them "" in place of the second Expression. 

Examples of Merge Tags with a Text Value
(surround these with quotes)

<< Matter.Number >>
<< Matter.Description >>
<< Matter.ResponsibleAttorney >>
<< Matter.Client.Name >>

Examples of Merge Tags with a Numeric Value
(do not surround these with quotes)

<< Matter.TrustBalance >>
<< Matter.OperatingBalance >>
<< Matter.Client.TrustBalance >>
<< Matter.Client.OperatingBalance >>
<< Matter.Client.PaymentProfile.InterestRate >>
<< Matter.Client.PaymentProfile.GracePeriod >>

Operator 

The operator defines how the expressions relate to each other. For example, are they equal/the same, or not? 

= Equal to Use with both text and numeric Expressions
<> Not equal to Use with both text and numeric Expressions
> Greater than Use with numeric Expressions only
< Less than Use with numeric Expressions only
>= Greater than or equal to Use with numeric Expressions only
<= Less than or equal to Use with numeric Expressions only

TrueText and FalseText 

TrueText refers to the text that will be displayed if the condition (relationship between the expressions) is satisfied.

FalseText refers to the text that will be displayed if the condition is NOT satisfied (this is the ELSE part of the statement).

TrueText and FalseText statements should be surrounded by quotation marks. 

If you want either the TrueText or FalseText to be empty (to not display anything), just use empty quotation marks "".

You can also use Clio merge field tags in your TrueText and FalseText.

Putting it all Together

Putting together all of the elements detailed above, a conditional statement that will display a message asking for a prepayment funds if the client's trust balance is zero can look something like this:

For more information on composing conditional statements for use in MS Word, click HERE.


Adding Conditional Fields to a Word Template

To add a conditional field in MS Word, ensure that your text cursor is located in your document where you want the conditional text to display, then click on the "Insert" tab then click on the "Quick Parts" icon  in the "Text" group. 

In the Quick Parts menu, click on the "Field" option. 

In the "Field" window, scroll through the "Field names" list and select "If". Enter your conditional statement into the "Field codes" text area then click "OK".

In your document, you will likely see the FalseText of your conditional statement. That is because the Word document doesn't know the value of your Clio merge field tags before Document Automation takes place. To make fields in your document stand out more clearly, you can change how fields are displayed in your Word document. 

Open the Word Options window by pressing Alt+f+t on your keyboard. In the Options window, click "Advanced" from the side panel then scroll down to the section "Show document content". There are 2 options here to help you quickly identify fields in your document: "Show field codes instead of their values" and "Field shading: Always".

Limitations and Syntax

  • The "Field codes" field has a character limit of 255 (including spaces), so the specific steps detailed above are only useful for displaying short pieces of information. To display longer text, you have a couple of options.

    1. Save the field to your document then paste in the longer text:

      Start by entering the outline of your conditional statement into the "Field" window without entering the long TrueText or FalseText, then click "OK" to add the field to your document.
      For example: 

      IF "<< Matter.Status >>" = "Open" "" ""

      If the field code is not already visible in your document (if you are seeing the field's Expression or FalseText instead), right click on the field and select "Toggle Field Codes". With the field code visible, click into the TrueText or FalseText quotes (where the long piece of text applies) then start typing in the text or paste it from another source.

    2. Use Clio Custom Fields containing the long text that you want to pull in to your document. 
      For example:

      IF "<< Matter.Status >>" = "Open" "<< Matter.CustomField.1 >>" "<< Matter.CustomField.2 >>" 

  • Conditional statements do not support special characters or quotation marks in the text that you use for your TrueText or FalseText.
    For example, the following statement will not work properly:

IF "<< Matter.CustomField.Pleading >>" = "guilty" "The defendant pleads "guilty"." "The defendant pleads "not guilty"."

To display text that contains quotation marks or special characters, you will have to add that information to Clio Custom Fields then use those merge fields for your TrueText and FalseText.   


Tips and Examples of Useful Conditional Statements

Using Clio Checkboxes to Determine what is Displayed

Using Clio Custom Fields, you can add custom checkboxes to your Contacts and Matters that can be used to determine what is displayed in your generated document. To reference a Clio checkbox, use the merge field tag in the place of the first Expression. The second Expression will be either "true" or "false" - "true" if the box is checked, "false" if the box is not checked. 

For example:

IF "<< Matter.CustomField.Checkbox >>" = "true" "This box is checked." "This box is not checked."

Using Clio Picklists to Determine what is Displayed 

Using Clio Custom Fields, you can add custom picklists to your Contacts and Matters that can be used to determine what is displayed in your generated document. To reference a Clio picklist, use the merge field tag in the place of the first Expression. The second Expression will match the custom option that should be selected.

For example:

IF "<< Matter.CustomField.Picklist >>" = "option1" "You selected option 1." "You did not select option 1."

To accommodate picklists with more than 2 options, see the section below, "Nesting Conditional Statements".

Nesting Conditional Statements (Multiple Conditions)

You can create conditional statements that consider multiple scenarios/conditions. "Nesting" a condition within another condition requires a few extra steps and specific syntax to work properly.

For example, to write a conditional statement that looks for all possible responses from a picklist with 4 options, follow these steps.  

  1. Click in your document where you want the condition to go, then press Ctrl+F9 on your keyboard to insert a blank field (2 curly brackets ).

  2. Within the brackets, type a space then begin typing the outline of the conditional statement (note that it is always important to have a space between all curly brackets and any other characters in your statement).

    The basic outline of this conditional statement should look like this:

  3. Click between the FalseText quotation marks then press Ctrl+F9 on your keyboard to insert another blank field. This blank field is where you will type in another conditional statement that will look for the second option in the list.

  4. Within the brackets of the second/nested field, type in the outline of the conditional statement to look for option2.

    Your nested conditional statement should now look like this:

  5. Repeat steps 3 & 4 but his time click between the FalseText quotation marks for the second condition before pressing Ctrl+F9 on your keyboard.

  6. Continue adding new conditional statements to the FalseText of each option condition until you have added the last option. In the FalseText for the last option, just enter the text or field that you would like to display if none of the conditions are satisfied. 

    The complete statement should look something like this:

    Or, for clearer visibility, the nested conditions can be colour coded as such:
    { IF "<< Matter.CustomField.Picklist >>" = "option1" "You selected option 1." "
    { IF "<< Matter.CustomField.Picklist >>" = "option2" "You selected option 2." "
    { IF "<< Matter.CustomField.Picklist >>" = "option3" "You selected option 3." "You selected option 4." }" }
    " }

Adding Line Breaks to TrueText and FalseText

If you need to break up the text that you are using for your TrueText or FalseText, you can add line breaks by directly modifying the field codes in your document. 

If the field code is not already visible in your document (if you are seeing the field's Expression or FalseText instead), right click on the field and select "Toggle Field Codes".

You will now see the entire field code and be able to edit the text and add line breaks.

Click into the text where you want the line breaks to go then press Shift+Enter to add a soft break.  

Troubleshooting Document Generation in MS Word

Due to limitations in how MS Word updates fields, you may not see your conditional fields updated appropriately after generating a document through Clio. In most cases, you will have to open the newly generated Word document and manually update all fields in order to see the appropriate values of your conditional statements. To do so, select all content in your document (using Ctrl+a) then hit F9 on your keyboard to update all fields in your document. You will then have to save the document and re-upload it to Clio.

If updating the fields in your generated Word document does not fix the problem, then you will need to determine if the conditional field has any errors. To do that, use your template to generate a PDF in Clio, then view the PDF. If the field appears correctly on the PDF, then you can be assured that your conditional field is working properly. If the field is not appearing correctly in the PDF, then you will need to go back to your template and look for problems in the field construction and syntax.


Advanced Document Automation Webinar

In under an hour, we demonstrate advanced MS Word techniques for adding conditional fields and form controls to your Word template. We also demonstrate how to add editing restrictions to your template. This advanced webinar is intended for users who are already comfortable with creating Word templates for use in Document Automation.

Review the Document Automation video for more information.