> 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/variables.md).

# Variables

Variables allow you to select data within your workflow. Some come from the Begin step or a module; others are values you save as the workflow runs. You can [define your own workflow variables](https://docs.middle.app/middle-docs/product/accounts/defining-workflow-variables.md) and use them in later steps.

## Variable Selector

JSON type: `global_var_selector`.

Selects a named value available at this point in the workflow or trigger. `expression` is its exact key, including capitalization. `props` optionally selects fields within that value. This parameter has no children.

For a workflow with an `input_record` input containing an `email` field, this returns that email address. If `input_record` is a foreign key, Middle follows it to the synced record before reading the field.

```json
{
  "type": "global_var_selector",
  "expression": "input_record",
  "props": ["email"]
}
```

For a declared workflow variable named `points`, this returns its current value. It is null until a step assigns it a value.

```json
{
  "type": "global_var_selector",
  "expression": "points"
}
```

### Where the values come from

| Source                  | JSON key in `expression`                      | Availability                                                                                                     |
| ----------------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| Begin step input        | The input field's key, such as `input_record` | Throughout the workflow. These fields do not need separate variable declarations.                                |
| Workflow variable       | The declared key, such as `points`            | Throughout that workflow execution. Starts as null; steps can assign and replace its value.                      |
| Module variable         | The variable's key                            | In that module's workflows, using the connected account's value.                                                 |
| Begin step's full input | `ROOT_INPUT`                                  | In assignments on the Begin step.                                                                                |
| Action result           | `ACTION_OUTPUT`                               | In that Action step's output assignments. Save the needed values in workflow variables to use them later.        |
| File Export result      | `FILE_OUTPUT`                                 | In that File Export step's output assignments. Save the needed values in workflow variables to use them later.   |
| Activity record         | `ACTIVITY`                                    | In an activity trigger's discard, requeue, and custom input parameters. References the synced record.            |
| Prior activity record   | `PRIOR_ACTIVITY`                              | In activity trigger parameters when the prior record version is included. Contains the previous record's values. |
| Start time              | `NOW`                                         | In workflows and triggers.                                                                                       |
| Now                     | `NOW_REAL`                                    | In workflows and triggers.                                                                                       |
| Null, true, false       | `NULL`, `TRUE`, `FALSE`                       | In workflows and triggers. These are values, not text.                                                           |

The dropdown shows the values available in the current context. Trigger parameters run before the workflow, so they cannot read that workflow's declared variables. Pass values through the trigger's workflow input instead. `ACTIVITY` follows the current synced record when read; `PRIOR_ACTIVITY` is the saved prior version.

### Selecting fields

`props` is an ordered path. For an object stored in a variable named `customer`, `"props": ["address", "city"]` selects `customer.address.city`. Use field keys from the input or variable's type, not their display labels. An omitted or empty `props` returns the entire value. A missing object field or related record returns null. Selecting a property that does not exist for the value's type can cause an error.

When selecting an object's foreign-key field, append `~ID` to the field key to read just the ID. For example, this returns the customer ID from a `sale` object with a `customer` foreign-key field. To read a foreign key's complete record instead, use `~OBJECT` as the next path element, such as `["customer", "~OBJECT"]`.

```json
{
  "type": "global_var_selector",
  "expression": "sale",
  "props": ["customer~ID"]
}
```

Older copied workflows can contain keys such as `WORKFLOW:2` for a step's saved output. Keep those keys when reading an older workflow; new workflows should use declared variables and output assignments.

### Now vs. Start time

**Now** is the time when this parameter is evaluated. Its JSON key is `NOW_REAL`.

```json
{
  "type": "global_var_selector",
  "expression": "NOW_REAL"
}
```

**Start time** is the time the workflow was queued or the trigger activity occurred. Its JSON key is `NOW`. It stays the same when a workflow is re-executed or a trigger is requeued. Use it when a retry should make the same time-based decision as the original attempt.

```json
{
  "type": "global_var_selector",
  "expression": "NOW"
}
```

Both return datetimes. Use [Convert Timezone of Datetime](https://docs.middle.app/middle-docs/product/accounts/workflow-parameters/dates-and-datetimes.md#convert-timezone-of-datetime) or [Format Date or Date Time](https://docs.middle.app/middle-docs/product/accounts/workflow-parameters/dates-and-datetimes.md#format-date-or-date-time) when you need a particular local date or display format.

## Parameter-scoped variable

JSON type: `parent_np_selector`.

Selects a value supplied by a surrounding array operation. These variables exist only inside that operation's per-item parameter; they are not workflow variables. `expression` is the full scoped key, and `props` can select a field from the value.

With `"output_name": "items"`, Map, Filter, Sort, First Match, and Reduce provide `items:value` for the current item and `items:index` for its position in the source array, starting at `0`. Reduce also provides `items:acc` for the accumulated value. Use different output names for nested operations so an inner operation does not hide the outer one's variables.

This complete Map parameter returns `[10, 20]`. The nested `parent_np_selector` reads each current item; it would not be valid on its own outside that Map.

```json
{
  "type": "map_array",
  "output_name": "items",
  "params": [
    {
      "type": "construct_array",
      "params": [
        {"type": "math_expression", "expression": "1"},
        {"type": "math_expression", "expression": "2"}
      ]
    },
    {
      "type": "math_expression",
      "expression": "{} * 10",
      "params": [
        {"type": "parent_np_selector", "expression": "items:value"}
      ]
    }
  ]
}
```

See [Array Manipulation](https://docs.middle.app/middle-docs/product/accounts/workflow-parameters/array-manipulation.md) for the child order and complete examples of each array operation.


---

# 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/variables.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.
