> For the complete documentation index, see [llms.txt](https://docs.middle.app/middle-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.middle.app/middle-docs/product/accounts/workflow-parameters/flow-control.md).

# Flow Control

Flow controls allow you to build out decision logic within Decision steps and Action steps. They can also be used anywhere else a parameter is configured, including trigger conditions. These parameters calculate values; an If parameter does not add a branch to the workflow by itself.

The JSON examples show complete parameter objects from the copied-workflow format. The order of children in `params` matters.

## If

**JSON type:** `comparison`. **Expression:** one of the comparison keys listed below. **Children:** the left value, followed by the right value when the comparison needs one. **Result:** true or false for a valid comparison.

Creates a boolean statement with a left and right comparison. For example, compare a member's status to `Active`, or compare the number of check-ins to `10`. The available comparison choices depend on the left parameter's type.

Both sides are evaluated before comparing them. Comparisons do not automatically trim text, ignore case, or parse numbers from text. Use [Text Manipulation](https://docs.middle.app/middle-docs/product/accounts/workflow-parameters/text-manipulation.md) or [Parse Number](https://docs.middle.app/middle-docs/product/accounts/workflow-parameters/constants-and-calculated-values.md#parse-number) first when needed. An invalid type or an error in either child still causes an error. Some comparisons accept null, as described below. Use [And](#and) to check for null before a comparison that requires a value.

### Comparison options

These are all the comparison choices. The JSON keys are case-sensitive.

#### String comparisons

Text comparisons are case-sensitive. `L` means the first child and `R` means the second child in this table. Text on the right must be a string, even when the left is a record's primary ID; a Text parameter can convert an ID to a string when necessary.

| Choice                           | JSON `expression`       | Meaning                                                                               |
| -------------------------------- | ----------------------- | ------------------------------------------------------------------------------------- |
| (String) is equal to             | `STRING_EQUALS`         | `L` and `R` are exactly the same text.                                                |
| (String) is not equal to         | `STRING_NOT_EQUALS`     | `L` and `R` are different.                                                            |
| (String) is contained within     | `STRING_IS_IN`          | `L` is a substring of text `R`, or an exact item in a string array `R`.               |
| (String) begins with             | `STRING_STARTSWITH`     | `L` starts with `R`.                                                                  |
| (String) ends with               | `STRING_ENDSWITH`       | `L` ends with `R`.                                                                    |
| (String) is not contained within | `STRING_NOT_IS_IN`      | `L` is not a substring or array item in `R`.                                          |
| (String) includes                | `STRING_INCLUDES`       | Text `L` contains substring `R`. This reverses the operands of “is contained within.” |
| (String) does not include        | `STRING_NOT_INCLUDES`   | Text `L` does not contain substring `R`.                                              |
| (String) does not begin with     | `STRING_NOT_STARTSWITH` | `L` does not start with `R`.                                                          |
| (String) does not end with       | `STRING_NOT_ENDSWITH`   | `L` does not end with `R`.                                                            |

Equality and inequality accept null: two null values are equal, and null is different from any string, including `""`. With null on the left, “begins with,” “ends with,” and “includes” return false; their negative comparisons return true. Prefix and suffix comparisons still require non-null text on the right.

For “is contained within,” the right side must be non-null; a null left side is not contained in text, but can match a null item in an array. For “includes,” a null right side is not included in text. The corresponding negative comparisons reverse those results. Empty text is a substring, prefix, and suffix of any string.

This example returns true because `Active` begins with `Act`:

```json
{
  "type": "comparison",
  "expression": "STRING_STARTSWITH",
  "params": [
    {
      "type": "template",
      "expression": "Active"
    },
    {
      "type": "template",
      "expression": "Act"
    }
  ]
}
```

This example also returns true. When the right side is an array, “is contained within” matches a whole item, not a substring:

```json
{
  "type": "comparison",
  "expression": "STRING_IS_IN",
  "params": [
    {
      "type": "template",
      "expression": "Active"
    },
    {
      "type": "splitlines",
      "params": [
        {
          "type": "template",
          "expression": "Active\nPending"
        }
      ]
    }
  ]
}
```

#### Array of Strings comparisons

The left side can be an array of strings, an empty array, or null. The right side is one string or null. These comparisons look for an exact item, not part of an item's text. A null right side matches a null item in the array. With null on the left, “includes” returns false and “does not include” returns true.

| Choice                              | JSON `expression`           | Meaning                                          |
| ----------------------------------- | --------------------------- | ------------------------------------------------ |
| (Array of Strings) includes         | `ARRAY_STRING_INCLUDES`     | The left array contains the right value.         |
| (Array of Strings) does not include | `ARRAY_STRING_NOT_INCLUDES` | The left array does not contain the right value. |

This example returns true:

```json
{
  "type": "comparison",
  "expression": "ARRAY_STRING_INCLUDES",
  "params": [
    {
      "type": "splitlines",
      "params": [
        {
          "type": "template",
          "expression": "Active\nPending"
        }
      ]
    },
    {
      "type": "template",
      "expression": "Active"
    }
  ]
}
```

#### Number comparisons

Use numbers on both sides. A numeric string such as `"10"` needs Parse Number first. Equality and inequality also accept null; two nulls are equal and null is not equal to a number. The four ordering comparisons return false when the left side is null. The right side must still be a non-null number.

| Choice                               | JSON `expression`               | Meaning                                 |
| ------------------------------------ | ------------------------------- | --------------------------------------- |
| (Number) is greater than             | `NUMBERLIKE_GREATER_THAN`       | Left is greater than right.             |
| (Number) is less than                | `NUMBERLIKE_LESS_THAN`          | Left is less than right.                |
| (Number) is greater than or equal to | `NUMBERLIKE_GREATER_THAN_OR_EQ` | Left is greater than or equal to right. |
| (Number) is less than or equal to    | `NUMBERLIKE_LESS_THAN_OR_EQ`    | Left is less than or equal to right.    |
| (Number) equals                      | `NUMBERLIKE_EQUALS`             | Left and right are equal.               |
| (Number) not equal to                | `NUMBERLIKE_NOT_EQUALS`         | Left and right are different.           |

This example returns true:

```json
{
  "type": "comparison",
  "expression": "NUMBERLIKE_GREATER_THAN_OR_EQ",
  "params": [
    {
      "type": "math_expression",
      "expression": "12"
    },
    {
      "type": "math_expression",
      "expression": "10"
    }
  ]
}
```

#### Date comparisons

Compare calendar dates with no time portion. After and before are strict: equal dates satisfy neither. Equality and inequality accept null. After and before return false when the left side is null, but require a non-null date on the right.

| Choice                 | JSON `expression` | Meaning                               |
| ---------------------- | ----------------- | ------------------------------------- |
| (Date) is after        | `DATE_AFTER`      | Left date is later than right date.   |
| (Date) is before       | `DATE_BEFORE`     | Left date is earlier than right date. |
| (Date) is equal to     | `DATE_EQUALS`     | Left and right are the same date.     |
| (Date) is not equal to | `DATE_NOT_EQUALS` | Left and right are different dates.   |

For older workflows, the runtime also accepts parseable date text or a datetime in a Date comparison. It takes the datetime's calendar date without converting its timezone. Invalid date text causes an error. Use [Date](https://docs.middle.app/middle-docs/product/accounts/workflow-parameters/dates-and-datetimes.md#date) or explicit date conversion in new parameters so the intended type is clear.

This example returns true:

```json
{
  "type": "comparison",
  "expression": "DATE_AFTER",
  "params": [
    {
      "type": "date",
      "expression": "2026-10-07"
    },
    {
      "type": "date",
      "expression": "2026-10-06"
    }
  ]
}
```

#### Datetime comparisons

Compare timestamps. Two timestamps with different timezone offsets can be equal if they represent the same instant. After and before are strict. Equality and inequality accept null. After and before return false when the left side is null, but require a non-null datetime on the right. A Date without a time portion is not a Datetime for these comparisons.

| Choice                   | JSON `expression`         | Meaning                                         |
| ------------------------ | ------------------------- | ----------------------------------------------- |
| (Datetime) is after      | `DATETIMELIKE_AFTER`      | Left timestamp is later than right timestamp.   |
| (Datetime) is before     | `DATETIMELIKE_BEFORE`     | Left timestamp is earlier than right timestamp. |
| (Datetime) is equals     | `DATETIMELIKE_EQUALS`     | Left and right represent the same instant.      |
| (Datetime) is not equals | `DATETIMELIKE_NOT_EQUALS` | Left and right represent different instants.    |

Older workflows may supply parseable timestamp text. Text without a timezone is interpreted as UTC. An existing datetime without a timezone is handled differently: when only one of the two datetime values has a timezone, the other is compared using that same timezone. If neither has one, their clock values are compared directly. Use explicit offsets in new parameters to avoid relying on these fallbacks. Invalid timestamp text causes an error.

This example returns true; both timestamps refer to the same instant:

```json
{
  "type": "comparison",
  "expression": "DATETIMELIKE_EQUALS",
  "params": [
    {
      "type": "datetime",
      "expression": "2026-10-07T09:00:00-07:00"
    },
    {
      "type": "datetime",
      "expression": "2026-10-07T16:00:00+00:00"
    }
  ]
}
```

#### Time comparisons

Compare time-of-day values with no date. Use [Time](https://docs.middle.app/middle-docs/product/accounts/workflow-parameters/dates-and-datetimes.md#time) or Construct Time rather than text. After and before are strict and return false when the left side is null. With a time on the left, the right side must be a non-null time. Equality and inequality can compare a time to null. When using timezones, both operands should either include an offset or both omit one; ordering a time with an offset against one without an offset causes an error. These comparisons do not treat the day as a loop: `01:00` is before `23:00` on the same clock, not two hours after it.

| Choice            | JSON `expression` | Meaning                               |
| ----------------- | ----------------- | ------------------------------------- |
| (Time) after      | `TIME_AFTER`      | Left time is later than right time.   |
| (Time) before     | `TIME_BEFORE`     | Left time is earlier than right time. |
| (Time) equals     | `TIME_EQUALS`     | Left and right times are equal.       |
| (Time) not equals | `TIME_NOT_EQUALS` | Left and right times are different.   |

This example returns true:

```json
{
  "type": "comparison",
  "expression": "TIME_BEFORE",
  "params": [
    {
      "type": "time",
      "expression": "09:00:00"
    },
    {
      "type": "time",
      "expression": "17:00:00"
    }
  ]
}
```

#### Boolean comparisons

Use true or false values, not the text `"true"` or `"false"`. Equality and inequality also allow null on either side. The unary choices use only the left child; do not include a right child in their `params` array.

| Choice                                 | JSON `expression`  | Meaning                                                                     |
| -------------------------------------- | ------------------ | --------------------------------------------------------------------------- |
| (Boolean) is equal to                  | `BOOLEAN_IS`       | Both sides are the same boolean value, or both are null.                    |
| (Boolean) is not equal to              | `BOOLEAN_IS_NOT`   | The sides differ, including a boolean compared with null.                   |
| (Boolean) is True (null raises error)  | `BOOLEAN_IS_TRUE`  | Tests a Boolean parameter for true. An explicit Null parameter is invalid.  |
| (Boolean) is False (null raises error) | `BOOLEAN_IS_FALSE` | Tests a Boolean parameter for false. An explicit Null parameter is invalid. |

“Is True” and “Is False” raise an error when the left value is null, including when it comes from a Boolean field. Use the null or truthiness comparisons below when missing values should produce a true or false result instead.

This example returns true and has no right child:

```json
{
  "type": "comparison",
  "expression": "BOOLEAN_IS_FALSE",
  "params": [
    {
      "type": "boolean",
      "expression": "BOOLEAN_IS_FALSE"
    }
  ]
}
```

#### Null, truthiness, and general equality

Truthiness asks whether a value counts as true in a condition. Null, false, zero, an empty string, an empty array, and an empty object are falsey. Other values are truthy. Text such as `"false"`, `"0"`, or a space is truthy because it is not empty. Null checks only test for null, not for an empty or zero value.

| Choice                                          | JSON `expression`   | Children    | Meaning                                               |
| ----------------------------------------------- | ------------------- | ----------- | ----------------------------------------------------- |
| Not null, not blank, not zero, or True (Truthy) | `VALUE_IS_TRUTHY`   | Left only   | True when the left value is truthy.                   |
| Null, or blank, or zero, or False (Falsey)      | `VALUE_IS_FALSEY`   | Left only   | True when the left value is falsey.                   |
| Is null                                         | `VALUE_IS_NULL`     | Left only   | True only when the left value is null.                |
| Is not null                                     | `VALUE_IS_NOT_NULL` | Left only   | True when the left value is anything other than null. |
| Equals                                          | `VALUE_EQUALS`      | Left, right | Compares the values for equality.                     |
| Not equals                                      | `VALUE_NOT_EQUALS`  | Left, right | Compares the values for inequality.                   |

The first four choices work with any parameter type. General equality is available for strings, primary IDs, numbers, dates, datetimes, booleans, times, string arrays, empty arrays, and null on the left. The right side accepts strings, numbers, dates, datetimes, booleans, string arrays, empty arrays, or null; use `TIME_EQUALS` and `TIME_NOT_EQUALS` to compare two times. Other arrays and objects support truthiness and null checks, not general equality.

General equality does not parse or convert text: the number `10` is different from the string `"10"`. It uses value equality, so true equals `1`, false equals `0`, and string arrays are equal only when their items and order match. Use the typed comparisons when you want the editor to require a particular type. An empty array is different from null.

This example returns true:

```json
{
  "type": "comparison",
  "expression": "VALUE_IS_NULL",
  "params": [
    {
      "type": "make_null"
    }
  ]
}
```

This example returns false because the number and string are different values:

```json
{
  "type": "comparison",
  "expression": "VALUE_EQUALS",
  "params": [
    {
      "type": "math_expression",
      "expression": "10"
    },
    {
      "type": "template",
      "expression": "10"
    }
  ]
}
```

## And

**JSON type:** `and`. **Expression:** unused. **Children:** one or more Boolean parameters, in order. **Result:** true only when all children are true.

Groups together IF statements where all need to be true to pass. Children are evaluated from top to bottom. Evaluation stops at the first false result, so later children are not evaluated. This lets an earlier condition protect a later condition from an invalid value, such as checking that a date is not null before comparing it.

With no children, And causes an error. Children should return booleans; And does not parse text such as `"false"` into false.

This example returns false. The first comparison returns false, so the second comparison is skipped:

```json
{
  "type": "and",
  "params": [
    {
      "type": "comparison",
      "expression": "NUMBERLIKE_GREATER_THAN_OR_EQ",
      "params": [
        {
          "type": "math_expression",
          "expression": "5"
        },
        {
          "type": "math_expression",
          "expression": "10"
        }
      ]
    },
    {
      "type": "comparison",
      "expression": "STRING_EQUALS",
      "params": [
        {
          "type": "template",
          "expression": "Active"
        },
        {
          "type": "template",
          "expression": "Active"
        }
      ]
    }
  ]
}
```

## Or

**JSON type:** `or`. **Expression:** unused. **Children:** one or more Boolean parameters, in order. **Result:** true when any child is true.

Groups together IF statements where only one needs to be true to pass. Children are evaluated from top to bottom. Evaluation stops at the first true result. If every child is false, the result is false. With no children, Or causes an error. As with And, children should return booleans.

This example returns true:

```json
{
  "type": "or",
  "params": [
    {
      "type": "comparison",
      "expression": "STRING_EQUALS",
      "params": [
        {
          "type": "template",
          "expression": "Pending"
        },
        {
          "type": "template",
          "expression": "Active"
        }
      ]
    },
    {
      "type": "comparison",
      "expression": "STRING_EQUALS",
      "params": [
        {
          "type": "template",
          "expression": "Pending"
        },
        {
          "type": "template",
          "expression": "Pending"
        }
      ]
    }
  ]
}
```

## Switch

**JSON type:** `switch`. **Expression:** unused. **Children:** alternating condition and result pairs, followed by one default result. **Result:** the value of the first matching result, or the default.

Allows you to build "if, then, default" logic where there is a condition tested and an output based on whether a condition is met. In JSON, `params` is ordered as `[condition, result, condition, result, default]`. There must be an odd number of children, with at least one child. A Switch with just one child returns that default value.

Conditions must return booleans. Switch checks them from top to bottom and stops at the first true condition. Only that condition's result is evaluated. If none match, only the default result is evaluated. Unselected results and later conditions are skipped. The result keeps the chosen child's type; it is not converted to text or a boolean. Result types must be suitable for the field using the Switch. Use Null as the default when no match should produce no value.

This example returns `10`: the first condition is false, the second is true, and the default `0` is skipped.

```json
{
  "type": "switch",
  "params": [
    {
      "type": "comparison",
      "expression": "NUMBERLIKE_GREATER_THAN_OR_EQ",
      "params": [
        {
          "type": "math_expression",
          "expression": "12"
        },
        {
          "type": "math_expression",
          "expression": "20"
        }
      ]
    },
    {
      "type": "math_expression",
      "expression": "25"
    },
    {
      "type": "comparison",
      "expression": "NUMBERLIKE_GREATER_THAN_OR_EQ",
      "params": [
        {
          "type": "math_expression",
          "expression": "12"
        },
        {
          "type": "math_expression",
          "expression": "10"
        }
      ]
    },
    {
      "type": "math_expression",
      "expression": "10"
    },
    {
      "type": "math_expression",
      "expression": "0"
    }
  ]
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.middle.app/middle-docs/product/accounts/workflow-parameters/flow-control.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
