---
schema_version: "1"
id: a9f7bdaa98c74bf9e5034c593c6b7d41e090dd47bb2ad7da510c519b8232f9ca
title: Flow Reference (<flow-ref/>)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/acb-component-flow-ref.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/acb-component-flow-ref
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4068f47fbf1d2028d580cdb23a4694168954ebf2279499ecb79d34fd381e0553
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Flow Reference (<flow-ref/>)

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Routes the Mule event to another flow or subflow, executes all processors in the referenced flow,
and then routes the event back within the same Mule application.

This process enables you to treat the entire referenced flow like a single component in your current
flow.

Flow Reference breaks the Mule application into discrete and reusable units. For example, a flow
that lists files on a regular basis might reference another flow that processes the output of the
List operation. Instead of appending all the processing steps to the flow that lists the files, you
can append a Flow Reference that points to the processing flow.

> [!WARNING] Use actual flow names to define the **Flow name** (`name`) attribute. Using dynamic
> values (DataWeave expressions, variables) to specify the referenced flow negatively affects
> performance. Also, MUnit tests and application analysis tools cannot work on dynamic references.

## Component XML

This component supports the following XML structure:

```xml
<flow-ref name="anotherflow" />
```

Flow Reference (<flow-ref/>) attributes are configurable through the UI and XML.

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Attribute XML</th><th>Description</th></tr></thead><tbody><tr><td><p><strong>Name</strong></p></td><td><p><code>name</code></p></td><td><div><div><p>The name of the flow that this component references.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>doc:id</code></p></td><td><div><div><p>Automatically generated identifier for the component.</p></div></div></td></tr><tr><td><p><strong>Target Variable</strong></p></td><td><p><code>target</code></p></td><td><div><div><p>Name of the variable in which you want to store message data. Names can only include numbers, characters, and underscores. For example, hyphens are not allowed in the name. See <a href="https://docs.mulesoft.com/mule-runtime/latest/target-variables">Enrich Data with Target Variables</a> in the Mule documentation.</p></div></div></td></tr><tr><td><p><strong>Target Value</strong></p></td><td><p><code>targetValue</code></p></td><td><div><div><p>Value of the data to store in the target variable. By default, the value is the message payload (payload). The field accepts any value that a variable accepts: any supported data type, DataWeave expressions, the keywords <code>payload</code>, <code>attributes</code>, and <code>message</code>, but not the keyword <code>vars</code>. See <a href="https://docs.mulesoft.com/mule-runtime/latest/target-variables">Enrich Data with Target Variables</a> in the Mule documentation.</p></div></div></td></tr></tbody></table>

## Considerations when Using a Target Variable

Setting the `target` variable in a Flow Reference component causes the original message to remain
unchanged. This means that any modification to the payload or to the variables that occur in the
referenced flow revert after the referenced flow finishes executing its processors, returning the
payload and variables to their original values.

Alternatively, if you do not define a `target` variable, any modification that occurs to the payload
or to the variables in the referenced flow persist after the referenced flow finishes its execution,
changing the original value of the payload or variables.

## Navigate to the Referenced Flow

You can open the flow that a Flow Reference component points to directly from the canvas, without
switching views manually. To open the referenced flow, right-click the Flow Reference component and
select **Go to Flow**. You can also press Ctrl+Alt+g (Windows) or Cmd+Option+g (macOS).

Anypoint Code Builder opens the target flow in the appropriate canvas:

- In application flows, the referenced flow opens in the flow canvas.

- In MUnit test flows, the referenced flow opens in the MUnit canvas if applicable.

If the referenced flow is in an imported Mule project dependency, you can open it in a read-only
canvas and view its read-only XML. You can inspect the flow and go to other flows in the dependency,
but you can’t modify the dependency flow or its XML.

This helps you trace and manage flow logic across modular designs, whether you’re building or
testing your application.

To find every flow that references a flow or subflow, see
[Find Flows That Reference a Subflow](https://docs.mulesoft.com/anypoint-code-builder/int-configure-components#find-referencing-flows).

## Examples

The following example configures an HTTP listener, updates the payload, sets a variable, and
references another flow by adding the target variable `flowReferenceVar,` which stores the result of
the secondary flow called by the Flow Reference component. This variable is then used in the main
flow by logging `vars.flowReferenceVar`:

```xml
<!-- Main flow -->
<flow name="mainFlow" >
  <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="test"/>
  <set-payload value="Original payload" doc:name="Set Payload"  />
  <set-variable value="1" doc:name="Set myVar=1" variableName="myVar"/>
  <!-- Flow Reference component with target variable flowReferenceVar -->
  <flow-ref doc:name="secondaryFlow" name="secondaryFlow" target="flowReferenceVar"/>
  <logger level="INFO" doc:name="Log payload" message='#["Payload = " ++ payload]'/>
  <logger level="INFO" doc:name="Log myVar" message='#["myVar = " ++ vars.myVar]'/>
  <logger level="INFO" doc:name="Log flowReferenceVar" message='#["flowReferenceVar = " ++ vars.flowReferenceVar]'/>
</flow>
<!-- Secondary flow that is referenced from Main flow-->
<flow name="secondaryFlow" doc:id="044ece19-aa71-4fc9-ad34-8df655dd59a8" >
  <set-payload value="Modified payload" doc:name="Update Payload" />
  <set-variable value="2" doc:name="Update myVar=2" variableName="myVar"/>
</flow>
```

The following log represents the output of the example application after its execution:

INFO LoggerMessageProcessor: Payload = Original payload INFO LoggerMessageProcessor: myVar = 1 INFO
LoggerMessageProcessor: flowReferenceVar = Modified payload

If you remove `target="flowReferenceVar"` from the Flow Reference component, the application returns
the following output:

INFO LoggerMessageProcessor: Payload = Modified payload INFO LoggerMessageProcessor: myVar = 2 INFO
LoggerMessageProcessor: flowReferenceVar = null

The logs are shortened to improve readability.

## Error Handling

When an error occurs inside a flow that is referenced by a Flow Reference component, the execution
of the referenced flow stops and the process transfers to the referenced flow’s error handler. If
the referenced flow does not have a configured error handler, the error is propagated to the flow
that contains the Flow Reference call so this flow’s configured Error Handler component processes
the error.

Target variables are not set when an error occurs because the execution of the flow stops and does
not end successfully.

## See Also

- [Mule Events](https://docs.mulesoft.com/mule-runtime/latest/about-mule-event)

- [Enrich Data with Target Variables](https://docs.mulesoft.com/mule-runtime/latest/target-variables)

- [How Transactions Affect Scopes and Routers](https://docs.mulesoft.com/mule-runtime/latest/transaction-management#tx_scopes_routers)
