# 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](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-versioning).

{% 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F955YqunISPFCHlDrJD7p%2Fflow%20variables%201.jpg?alt=media&#x26;token=4315895f-a1a0-4b39-a6ae-084460e49913" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FKqMUyLrsqbdfbtE51DZB%2Fflow%20variables%202.jpg?alt=media&#x26;token=d85a0144-137b-43db-b5c7-183432022bd2" alt="" width="375"><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FWHbZDChcNvdNwk2mY3vY%2Fflow%20variables%201a.jpg?alt=media&#x26;token=c7311dd9-71b7-463f-8b7d-a4e60a909ada" 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`:&#x20;

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fd0ZPRYRV2DVkf9smaviH%2Fflow%20variables%209a.jpg?alt=media&#x26;token=ac1fa4fe-a0bc-4671-8c00-67dd7a0340d6" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Feu0mQaBiEBvpfujVKqLj%2Fflow%20variables%209b.jpg?alt=media&#x26;token=1aadf67f-9e8b-4b2a-ac1d-31ac9fb2264e" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FyrIEEl6rCHDP6tSz8BEi%2Fflow%20variables%209c.jpg?alt=media&#x26;token=385b629b-9048-4581-976b-8fb5b62125ae" 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.&#x20;

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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Flw1854b0P2i8UssdNsSC%2Fflow%20variables%207.jpg?alt=media&#x26;token=88e21b0f-aa5c-4e06-8b9e-9ebc907759eb" alt=""><figcaption></figcaption></figure>

We could define a static value here; [obtain values dynamically from a payload](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/payload-variables), 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](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-variables-in-custom-scripts) (which means you can manipulate these values however you need) and also in [field mapping transformations](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-and-meta-variables-in-mapping-transformations). &#x20;
{% 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FgKmfPQGUvuQebMJmUu1k%2Fflow%20variables%208.jpg?alt=media&#x26;token=22f03f7d-0975-4dc4-91a4-b5143d633f3c" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FMDCzhkuNckhQbY9LkzmS%2Fflow%20variables%209.jpg?alt=media&#x26;token=c92f924d-908d-40a3-8b5d-5c0c0813bea3" 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](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-variables-in-custom-scripts).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-variables-in-a-process-flow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
