# Flow variables

## Introduction

If your process flow includes a [connection shape ](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/connector-shape)that's configured for an endpoint where a variable can be entered, you'll probably be used to entering a static value to be applied for that step - for example:

![](https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F7Dyk2B6US70FC3uBdmxZ%2Fvariable%20eg1.jpg?alt=media\&token=ca51139c-d1c0-4eb0-a30b-94f3c2728931)

You might also be familiar with [obtaining variable values dynamically, from a payload](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/payload-variables). However, **flow variables** provide another level of flexibility.&#x20;

Flow variables provide the ability to define variables at the process flow level, and then reference these values throughout the entire process flow. You set a flow variable once, and it is applied throughout the entire process flow, wherever it is referenced.&#x20;

When flow variables are modified - either manually or via a script - those updates are applied anywhere in the process flow where they are referenced, automatically.

{% 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 %}

## Need to know

Before you start working with flow variables, there are a couple of important points to understand regarding [process flow versions](#process-flow-versions) and [update persistence](#update-persistence).

### Process flow versions

Flow variables are version-specific. For example, if you add flow variables to the current `draft` version and later restore an inactive version to `draft`, any defined flow variables won't be present. So, make sure you're updating the correct version of a process flow. For more information, please see our [Process flow versioning](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-versioning) page.

### Update persistence

If you update a flow variable [via a script](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-variables-in-custom-scripts), those updates persist for the duration of the flow run. Once the process flow has been completed, default values are restored.

## Using flow variables

Please see the following pages:

* [Adding & managing flow variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/adding-and-managing-flow-variables)
* [Referencing flow variables in a process flow](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables/referencing-flow-variables-in-a-process-flow)
* [Using 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)
* [Referencing flow variables in 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)

{% hint style="info" %}
When defining variables you can 'mix and match' [payload](#variables-and-parameters-from-payload-syntax), [metadata](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/payload-variables#variables-and-parameters-from-payload-metadata) and **flow** variables. For example:

![](https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FO9qBWPxzLHTy6QWjKprQ%2Fmix%20variables%20example.png?alt=media\&token=f3e960b3-9849-4237-9730-2e2fb9baff85)
{% endhint %}

## Related information

* [Payload variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/payload-variables)
* [Metadata variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/metadata-variables)
* [Generating dynamic cache keys with variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape/generating-dynamic-cache-keys-with-variables)
