enfr

Conditions

Updated: 2017-04-05

Conditions help you to display or hide parts of a template based on whether the condition is met within the open tax return. 

Of course, you need to understand how to open the Template Editor and test your code. Learn about these in the Template Editor topic. And, most conditions begin with a field code or constant. Please read the help topic on Field codes before continuing. 

For a list of hidden and useful codes that you cannot find on forms, see the Template code help topic.

Constructing a condition

All conditions contain an opening and closing tag:

  1. A condition opens with a field code prefixed with a # (number sign). For example: {{#CurrentClient.Info.ID.Title}}
  2. Close a condition with the {{/end}} tag or a closing version of the opening declaration {{/CurrentClient.Info.ID.Title}}, using a / (forward slash) instead of a # (number sign).

Anything that appears in between those opening and closing tags will show or hide based on whether the condition is met.

Example A: Show text only if the taxpayer HAS contributed to an RRSP

This example shows you how to quickly test whether there is a number or value in the field.

  1. First, open a tax return and find the field you want to use to construct the condition. In this case, we are going to find the total of the contribution fields on the RRSP worksheet in TaxCycle T1.
  2. Click once in the field, then click on the field code that appears in the blue bar at the bottom left of the window to copy it to your clipboard.
  3. Open the Template Editor.
  4. Click New to start a blank template.
  5. Select the same year as the file you have open and click OK to start the template.
  6. Paste the field code you copied earlier into the template: {{CurrentClient.RRSPContributions.ClientRRSP.M[0]}}
  7. Add a # (number sign) after the {{ two opening braces: {{#CurrentClient.RRSPContributions.ClientRRSP.M[0]}}
  8. Next, create the closing tag. Copy this piece of code, then paste it and change the # (number sign) to a  / (forward slash): {{/CurrentClient.RRSPContributions.ClientRRSP.M[0]}} (Or, use the closing tag {{/end}} to close the condition.)
  9. Finally, type some text between the opening and closing tags, so you can see whether it shows or hides depending on what's in the field.

Example B: Show text only if the taxpayer HAS NOT contributed to an RRSP

What about if you wanted to do the reverse? Only show text if someone has not contributed to an RRSP this year? You can add arguments to the condition to test the value in the field. In this case, we will show you how to test that the value in the field is zero. 

  1. Start with the condition we built in Example A.
  2. In the opening tag, add a = (equals sign) and the number 0 (zero) before the }} closing braces: {{#CurrentClient.RRSPContributions.ClientRRSP.M[0] = 0}}

A word about whitespace

As long as you keep the field code and the pairs of {{ }} double braces together, it doesn't matter whether you add or remove the whitespace inside a statement.

For example, these two work just as well.

{{#CurrentClient.RRSPContributions.ClientRRSP.M[0]=0}}

{{ # CurrentClient.RRSPContributions.ClientRRSP.M[0] = 0 }}

This will not work:

{ {# CurrentClient.RRSPContributions. ClientRRSP.M[0] = 0 } }

The spaces between the {{ }} double braces and within the field code will break the statement.

Simplifying your code

If you are creating a section where all the conditions within that section address the same part of the tax return, you can declare parts of the conditions and have them apply to the whole segment. See also the section on "Breaking up field codes" in the Field codes and constants help topic.

For example, pull out {{# CurrentClient}} and then add an {{/end}} code to wrap around the whole segment, then remove CurrentClient from all statements.

 

Example C: Simplified field code

  1. Pull out {{# CurrentClient}} and then add an {{/end}} code to wrap around the whole segment, then remove CurrentClient from all statements.
  2. If all the conditions apply to the same form, you can do the same thing with the form name, in this case {{# RRSPContributions }}.

Operators for building logic

Operator Description

and

Tests that both statements are true.
or Tests that either statements are true.
> (greater than) Tests that the value of the first statement is larger than the value of the second statement.
< (less than) Tests that the value of the first statement is smaller than the value of the second statement.
>= (greater than or equal to) Tests that the value of the first statement is larger than or equal to the value of the second statement.
<= (less than or equal to) Tests that the value of the first statement is smaller than or equal to the value of the second statement.
= (equal) Tests that the statements produce identical results.
!= (not equal) Tests that the statements produce different results.
not()

Wrap a field or statement in not() to indicate that it is the opposite. This is particularly useful when when writing a condition for an empty field. For example, to show something when the transit number field on the T1DD is empty:

{{not(CurrentClient.T1DD.WITB.BranchNumber)}}

isblank()
or
isempty()

Tests whether a field is blank. Especially useful when testing for the presence of a date in a field. For example, to check whether that there is no spouse date of death on the Info worksheet:

{{isblank(CurrentClient.Info.Filing.SpouseDateOfDeath)}}

Combine this with the not() function to do the reverse, test whether the field has something in it. For example, to test that there is a spouse date of death on the Info worksheet:

{{not(isblank(CurrentClient.Info.Filing.SpouseDateOfDeath))}}

 

Note: There is no "else" operator, you need to reverse the condition.

Example D: Show text only if the RRSP contribution is greater than, less than a certain amount or field

What about if you want to show a section because someone has a contribution greater than or less than a certain amount, or another field on the return? (Note, this section will use the simplified code to better show how the statements.)

  1. In the opening tag, use the > (greater than) or > (less than sign) before the }} closing braces: {{# CurrentClient.RRSPContributions.ClientRRSP.M[0] < 2000}}
  2. Place either an amount, or a field code after then greater than or less than sign and before the }} closing braces: {{#CurrentClient.RRSPContributions.ClientRRSP.M[0] > CurrentClient.RRSPContributions.PriorYearRRSPLimit.M[10]}}

Date comparison and math

Learn how to format and code that returns a date in the Field codes help topic. You can find a list of date constants in the Dates help topic.

Example E: Compare dates

  1. To specify date to which you want to compare, use the following format: {{date(YYYY, MM, DD)}} or {{date(2017, 02, 18)}}
  2. Use dates in calculations. {{ format(today() - CurrentClient.Info.Filing.SigningDate, "dd") }} calculates how long ago the return was signed.
  3. Use constants in a calculation to create a date {{date(Constants.CurrentTaxationYear+1, 06, 15)}}

 

Combining operations

You can also use parentheses to group statements together and compare them. 

Example F: Ontario special benefits

A good example is when you need to combine an income threshold with something like residency:

  1. Create the income threshold condition. For example, T1.Income.TotalIncome < 30000.
  2. Add the and operator.
  3. Wrap two conditions to check for Ontario for residency in () (parentheses), using or between the two conditions. For example, (Info.Residency.ProvinceDec31="Ontario" or Info.Residency.ProvinceCurrent = "Ontario").

How to find the values for check boxes

Creating conditions is fairly straightforward when you are evaluating a numerical value or comparing field codes, but it becomes more challenging when you need to figure out the value assigned to check boxes.

Example G: The client has designated a property as a principal residence

In particular when working with check boxes that can have one, multiple, or no possible answers, you will need to test that one of the boxes was checked.

  1. Create a condition for each box on in the group. For example, S3.PrincipalResidence.Designation = "SomeYears", S3.PrincipalResidence.Designation = "AllYears" and S3.PrincipalResidence.Designation = "Properties".
  2. (Optional) wrap each condition in () (parentheses).
  3. Between the parentheses, insert and or or, depending whether all the boxes must be checked, a few of them or only one.

For example, in Example E, above, you have to figure out that the check boxes have the values of AllYears, SomeYears and Properties. These values do not appear on screen because the text associated with the check box on the form is usually different than the value behind the scenes.

To display the value of a check box, add the the box to the Data Monitor:

  1. Check any one of the boxes in the list and don't move another field, so that one of the boxes in the list remains in focus.
  2. Click the plus sign on the far right of the data monitor to add the field to the Data Monitor. 
  3. The field name or line number shows on the left side of the Data Monitor.
  4. The value for the box that is currently checked is on the right side. This is the exact value to use when creating a condition with that check box. Check each box one at a time to see its value.

Add a group of check boxes to the Data Monitor to see the value for each box.

Most check boxes in TaxCycle allow you to select only one from the list, like the principal residence question on T1 Schedule 3. These style of check boxes have a single name in the left side of the data monitor and different values associated with each box. 

Other check boxes allow you to select all that apply to a question. Such as the questions in Part A of the T1135. Behind the scenes, these are different. Each box has a different name and value, so you need to add each box to the Data Monitor to see the value, rather than adding just one and switching between them.