Testing with If-Then Conditional Statements

Liz Sanderson
Liz Sanderson
  • Updated

Introduction

Conditional Values are tests or conditions using one or more test clauses, which evaluate values or expressions based on a wide range of available operators and test types. The test clauses are connected with logic - combinations of AND, OR, and NOT, with parentheses to define evaluation order.

Conditional values take the form of If, Else If, and Else statements. The If statement is read first; if a feature passes the statement, it will follow the action determined by that condition. If the feature fails the If condition, it will be tested against the Else If statement.

A feature that passes an Else If statement will take on that action. If the feature fails, it will move onto the next Else If statement or the final statement: Else.

A final Else statement determines the action for all features that have failed the previous tests or conditions. This includes missing, null, or empty values within the tested attribute.

Setting Conditional Actions

A variety of transformers have the capability to set conditional actions. These are located in the drop-down menu for setting a parameter value.

dialog.png

Selecting "Conditional Value..." in the AttributeManager transformer will expose an "If, Else If, Else" dialog (shown below). Double-clicking a row displays a Tester-style dialog, allowing users to create conditions to test the data against.

The Parameter Condition Definition dialog allows a user to create a test condition and an output for a feature that passes that condition.

Using Conditional Actions

Conditional values are commonly used for setting attribute values; for example, when you need to map or set an attribute in relation to the value of one or more existing attributes. They are useful because they allow for conditions that are more complex than what can be handled in an AttributeValueMapper.
Conditional actions are applied within a single transformer and do not affect the number of output ports created. This allows a user to enter numerous possible values without cluttering or complicating the workspace. Tests can include multiple variables with multiple conditions by using AND/OR statements.

Examples of when to use Conditional Values

  • Determining attribute values based on the value of one or more other attributes
  • Using the TestFilter with multiple outputs
  • Using multiple Testers
  • Using User Parameters to filter or calculate attribute values

Example Workspaces

To follow along, download the example workspace from the Files section of this article. There are two workflows in the example workspace; both use conditional values within the Attribute Manager.

Example 1: Conditionals within a Tester 

Enable the first bookmark (right-click the bookmark header and select Enable all Objects in Bookmark) and run the workspace.

The workflow in this bookmark uses conditional values to determine the size of a park: Tiny, Small, Medium, or Large. The park areas are calculated from the park areas read from a Park MITAB file. Each feature has a park area calculated. The size constraints for the first workflow in square meters are:

dialog.png

Example 2: Conditionals with a User Parameter

Disable the first bookmark from step 1 and enable the second bookmark. Set the workspace to 'Run with Prompt'. Run the workspace and select 'yes' or 'no' for dog parks; the default value is 'yes'.

This workflow utilizes a User Parameter with conditional values to determine the size of a park, using the user's input to select either dog or non-dog parks. An area of 20,000 square meters is used to divide between the Small and Large parks. Parks that do not pass the Dog Park yes-or-no test are given the attribute value of "Unwanted Park".

dialog.png

A composite test was used for each output value to determine if a park meets the requirements. Composite tests combine three or more tests within a single condition and consist of AND/OR statements to combine the results. In the above dialog, the test condition evaluates if the park is a dog park (Y/N), if the user wants a dog park (Y/N), and if the park is of a certain size (smaller or larger than 20,000).

dialog.png

To create a composite test such as the one above, enter all test clauses and add the logic as you go, including parentheses to control the logic order. Select from the drop-down menu, or type directly into the Logic column fields. Alternatively, after the tests have been written, open the Composite Expression disclosure and edit the Composite Test.

A wide range of conditional operators are available.

Was this article helpful?

We're sorry to hear that.

Please tell us why.

As of January 14th, 2026, comments on knowledge base articles have been closed. To make sure questions don’t get missed and to enable more community support, we’ve moved discussions to the FME Community. If you have a question or a comment about this article, please create a new post or create a support ticket.