Follow
"IF" Statements Overview

You can use "IF" statements in general programming languages.

You can use "IF" statements in Workfront to compare, format, and string together fields of data for both reporting and custom data purposes. Also, thinking mathematically about "IF" statements leads to a better conceptual understanding since variables for expressions are commonly used.

Recommendations for "IF" Statements

Consider the following before creating an "IF" statement:

  • We recommend a basic understanding of any general programming language, but we do not require it, for this guide.
  • We require an advanced understanding of the Workfront text mode syntax. This helps with grasping the terminology of the Workfront API and with understanding the syntax of custom data in these specific formats.
    For information about the Workfront API, see "API Basics."
    For information about using text mode, see "Understanding Text Mode."
  • You can build "IF" statements for the following Workfront elements:
    • Views
    • Groupings
    • Calculated Custom Fields
  • You cannot build "IF" statements for filters. This results in a “Whoops” error in Workfront.
  • The Support Team does not help with building custom data. You can contact the Support Team after you build the custom fields or columns and you are not seeing the desired results. For help building an expression, please contact your Account Executive to inquire about our consulting options.
  • We recommend writing these expressions in a text editor first, such as Sublime or Visual Studio Code, because this helps you see data more clearly than would appear in Workfront.

Components of an "IF" Statement

You can build "IF" statements in Workfront using the following format: 

IF(Condition,True Expression,False Expression)

The components of an "IF" statement are: 

  • IF = This is the Workfront calculated data expression for “function.” Similar to the SUM and PROD expressions, this first tells the system to understand the function as an "IF" statement. Always use capital letters for "IF" in this statement.
    For a list of all calculated data expressions, see "Understanding Calculated Data Expressions."
  • Condition = This is the condition that the Workfront variable must meet and it is the foundation for this equation. Everything that can be later specified in the equation depends on the condition. You can use a number of references, comparisons or mathematical expressions to start an equation. Some examples of conditions are:
    • A date is greater than another date on a specified object.
    • A status equals one of the available statuses on a specified object.
    • A task is lesser than or greater than a certain percentage.
  • Condition Operator = this is the operator that helps you build the condition of your "IF" statement. For example, "is equal to" or "is greater than" are condition operators. For a list of condition operators that you can use in statements, see "Condition Operators in Calculated Custom Expressions."
  • TrueExpression = This is the "True" variable, which tells the equation which indicator to display once the criteria of the condition are met (true indicators).
  • False Expression = This is the "False" variable, which tells the equation which indicator to display when the criteria of the condition are not met (false indicators).

In the following example, the original statement format is used to write a simple data expression for an "IF" statement. The expression compares two different date fields in Workfront followed by a True/False result as a data string:

IF(Projected Completion Date>Planned Completion Date,"Off Track","On Track")

In everyday speech, this statement would mean:

“IF the Projected Completion Date of my object is ‘Greater Than’ the Planned Completion Date of my same object, then display the words ‘Off Track’ in this field, otherwise display the words ‘On Track.’”

Build Calculated Fields in Custom Forms or Custom Columns Using "IF" Statements

You can build "IF" statements in a calculated field either in a custom form, or in a custom column.

There is a difference in the syntax you use in a calculated custom form vs a calculated custom column. Refer to the following examples:

Single "IF" Statements

The following are examples of a calculated custom field and its corresponding column using an "IF" statement:

  • Calculated custom field: 

When building a custom field, use the following syntax for an "IF" statement:

IF(Projected Completion Date>Planned Completion Date,"Off Track","On Track")
  • Calculated custom column: 

When building a custom column, you should use the following syntax for the "IF" statement in the valueexpression line:

valueexpression=IF({projectedCompletionDate}>{plannedCompletionDate},"Off Track","On Track")

Multiple "IF" Statements

Multiple "IF" statements can be put together with the following statement to build a more complex and dynamic expression:

IF(Condition1,True Expression,IF(Condition2,True Expression,False Expression))

Notice, there is now no false statement for the first "IF". Instead, we replaced it with the start of a second IF.

The following are examples of a calculated custom field and its corresponding custom column using multiple "IF" statements:

  • Calculated custom field:
    IF(Projected Completion Date>Planned Completion Date,"Off Track",IF(Planned Completion Date>Projected Completion Date,"Off Track","On Track"))
  • Calculated custom column:
    valueexpression=IF({projectedCompletionDate}>{plannedCompletionDate},"Off Track",IF({plannedCompletionDate}>{projectedCompletionDate},"Off Track","On Track"))

In this example, the same thing has been accomplished by putting two different criteria variables together.

You can further explore these options by rebuilding these examples in your own environment.

The best way to learn this is by experimenting with various fields and scenarios. Also, become familiar with the API Explorer, which reveals the field names that can be used. For information on the API Explorer, see "API Explorer."

For more information about Workfront syntax for text mode coding, see "Understanding Calculated Data Expressions."

This article last updated on 2019-02-25 18:51:57 UTC