> For the complete documentation index, see [llms.txt](https://doc.wearepatchworks.com/product-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-variables-in-a-process-flow.md).

# Referencing flow variables in a process flow

## Introduction

The steps required to reference flow variables in a process flow can be summarised in two stages:

* [Stage 1: Define flow variables that can be referenced](#stage-1-define-flow-variables-that-can-be-used)
* [Stage 2: Add references to defined flow variables in process flow steps](#stage-2-add-references-to-defined-flow-variables-in-process-flow-steps)

## Stage 1: Define flow variables that can be used

Any flow variables that you want to reference from process flow shapes should be added as variables within the **process flow settings**. To do this, follow the steps below.

**Step 1**\
Access the process flow that you want to update and [make sure that you're switched to the required version](/product-documentation/process-flows/building-process-flows/process-flow-versioning.md).

{% hint style="info" %}
Typically, you would update the **draft** version, then deploy changes when you are ready.
{% endhint %}

**Step 2**\
Select settings (the cog icon) from the actions bar:

<div align="left"><figure><img src="/files/yE8uSKC64RpgD3kUrJwz" alt="" width="306"><figcaption></figcaption></figure></div>

**Step 3**\
Look for the **variables** section in the **flow settings** panel - for example:

<div align="left"><figure><img src="/files/Jcxq2nCa3XIlcLouZUqY" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 4**\
Click the **add new variable** button:

<div align="left"><figure><img src="/files/W9gO1aYdVzsM9BZrDnhG" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 5**\
In the **name** field, enter the name (i.e. the API parameter name) of this variable. For our example, the variable is named `customerID`:

<div align="left"><figure><img src="/files/CEMljLQNhOH9pCTw1Ku2" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 6**\
Click in the **select a type** field and select the data type for this variable:

<div align="left"><figure><img src="/files/gWlIYcVBFNxbbjPrj0c1" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 7**\
Enter the required value to be used wherever this variable is found in the process flow - for example:

<div align="left"><figure><img src="/files/4RHaqD2YYNZGe0T1RRw4" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 8**\
Add all required flow variables in the same way, then save changes.

## Stage 2: Add references to defined flow variables

Having defined your required **flow variables**, they can be referenced throughout the system - for example, in scripts or as variable values.

The example below shows how this works. A `GET single order` endpoint has been configured to expect a `customerID` variable, and then how this variable is surfaced in connection shape settings when this endpoint is used:

<figure><img src="/files/1rkNXjABCRlWFlbi43Qf" alt=""><figcaption></figcaption></figure>

We could define a static value here; [obtain values dynamically from a payload](/product-documentation/process-flows/building-process-flows/dynamic-variables/payload-variables.md), or reference an existing **flow variable**. The steps below show how to reference a flow variable.

{% hint style="info" %}
You can also reference flow variables in [custom scripts](/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-variables-in-custom-scripts.md) (which means you can manipulate these values however you need) and also in [field mapping transformations](/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-and-meta-variables-in-mapping-transformations.md).
{% endhint %}

**Step 1**\
In your process flow, access settings for the connection shape that you want to update with a flow variable:

<div align="left"><figure><img src="/files/biztZ3GpeqKqvsOZcDMz" alt="" width="322"><figcaption></figcaption></figure></div>

**Step 2**\
Look for the **variables** section in the **settings** panel - for example:

<div align="left"><figure><img src="/files/zg276v4VHyFokdgF3twi" alt="" width="353"><figcaption></figcaption></figure></div>

To use a **flow variable** here, the expected variable must correlate with a variable that you added in [stage 1](#stage-1-define-flow-variables-that-can-be-used). Notice that the example above is expecting a **Customer ID** variable, which correlates with the `customerID` flow variable that we added in step 5 of [stage 1](#stage-1-define-flow-variables-that-can-be-used).

**Step 3**\
Use the syntax below to reference a flow variable:

```
{{flow.variables.variable}}
```

...where the `variable` element should be replaced with the name of the **flow variable** defined in process flow settings ([stage 1](#stage-1-define-flow-variables-that-can-be-used)). Using our example, this would be:

```
{{flow.variables.customerID}}
```

**Step 4**\
Save changes. Now when this process flow runs, the value defined in process flow settings will be passed in for this variable.

{% hint style="info" %}
Flow variable values can also be updated by custom scripts. For further information please see [Referencing flow variables in custom scripts](/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-variables-in-custom-scripts.md).
{% endhint %}
