# Route shape

## Introduction

The **route** shape is used for cases where a process flow needs to split into multiple paths, based on a given set of conditions. Conditions are defined based on any fields found in the schema associated with your source data, so the scope for using routes is huge.&#x20;

To define multiple routes for your process flow you must:

1. Add a **route shape**.
2. Configure the **route shape** to add required routes and conditions.
3. Build the flow for each configured route by add [shapes](https://doc.wearepatchworks.com/product-documentation/~/changes/J8IbZkP6ASUZu2oBhGi2/process-flows/building-process-flows/process-flow-shapes) in the usual way.

{% hint style="info" %}
By default, multiple routes are processed in parallel when a process flow runs.&#x20;
{% endhint %}

{% hint style="warning" %}
If a route shape is added without route conditions, incoming data flows down ALL defined routes.
{% endhint %}

## Accessing route shape settings

## Accessing route shape settings

When you add a **route** shape to a **process flow**, the shape is added to your canvas with two placeholder route stems - 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%2FWqByWaNBciI1lfk8YDKq%2Froute%20shape%202.png?alt=media&#x26;token=27280069-e89f-4827-b1e4-2903132a60fa" alt="" width="319"><figcaption></figcaption></figure></div>

To configure these routes (and add more if needed) click the 'cog' icon associated with this shape to access [route settings](#configuring-route-data-for-a-new-route-shape).&#x20;

## Configuring route data for a new route shape

Follow the steps below to configure **route data** for a **route** shape.

**Step 1**\
Select a **source integration** and **endpoint** to determine where the incoming payload for the route shape is coming from - 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%2FnUadL9cHm47MPX7omPkI%2Froute%20shape%203.png?alt=media&#x26;token=9dd1d471-9d22-43a4-9a26-a58344a9d949" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 2**\
Select a **routing method** to determine what should happen if a payload record matches conditions defined for more than one route:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F4kOPOMjtAprshmf7yHrN%2Froute%20shape%204.png?alt=media&#x26;token=3498df0a-a8b5-4ea5-b2e8-a640e34217b4" alt="" width="375"><figcaption></figcaption></figure></div>

These options are summarised below:

| Option                           | Summary                                                                                                                              |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| Follow all matching routes       | If a record matches defined conditions for multiple routes, send it for onward processing down all matched routes.                   |
| Follow first matching route only | If a record matches defined conditions for multiple routes, send it for onward processing down the first matched route, but no more. |

<details>

<summary><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FuKTXJEY34CVnak6PxrOz%2Fexample%20icon%202.svg?alt=media&#x26;token=7c8af2c5-9519-4757-bea9-172569a023bd" alt="" data-size="line"> Example</summary>

To help understand how these options are used, consider an example where two routes are defined:

* Route 1 is to send all orders where the `product_type` ordered is `shoes` to Warehouse 1
* Route 2 is to keep all orders where the `product_type` ordered is `boots` to Warehouse 2

But what should happen with an order that includes **both** shoes and boots?&#x20;

* If we choose to **follow all matching routes**, then this order will flow down both routes - ending up in the payload for Warehouse 1 and Warehouse 2.&#x20;
* If we choose to **follow first matching route only**, this order will only flow down route 1 - ending up in the payload for Warehouse 1.

</details>

**Step 3**\
Click the 'edit' icon associated with the first route:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FCetYSlMEtiqjXso4FDLz%2Froute%20filters%200.png?alt=media&#x26;token=d0793f1f-cc70-448f-9034-4d36402dff54" alt="" width="350"><figcaption></figcaption></figure></div>

**Step 4**\
Enter your required name for this route - it's a good idea to ensure this provides an indication of the route's purpose. 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%2FrSJHJqm4Sl5RBS3CPR4c%2Froute%20filters%201.png?alt=media&#x26;token=f0a71698-ecef-4424-8ad3-958afad303eb" alt="" width="355"><figcaption></figcaption></figure></div>

**Step 5**

If you intend to define multiple rules/filters for this route, select the required operator from the **filter logic** dropdown field:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F0rOyjPbe3f6k5NdUKQLI%2Froute%20filters%202.png?alt=media&#x26;token=5ff66080-d475-4ebb-9b05-b26504200305" alt="" width="353"><figcaption></figcaption></figure></div>

* Select `AND` so all defined filters must apply for a match
* Select `OR` so any one of the defined filters will result in a match

{% hint style="info" %}
If you only need to define one filter, just leave the default setting in place (it has no effect).
{% endhint %}

**Step 6**\
Click the **add new filter** button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FWRg8jJRDGNqD43K9x63D%2Froute%20filters%203.png?alt=media&#x26;token=bdfe0193-f28d-4a41-93d4-1807fac98056" alt="" width="531"><figcaption></figcaption></figure></div>

**Step 7**\
Filter settings are displayed:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F5bRSODgGDJy9iwu1m8Ln%2Froute%20filters%204.png?alt=media&#x26;token=3c460638-2277-4fe2-a889-ba66099ea0c2" alt="" width="536"><figcaption></figcaption></figure></div>

From here, you can select a **field** (from the **data schema** associated with the **source endpoint** selected in step 1) - 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%2FysvKOwsCNNuYOYcktgmz%2Froute%20filters%205.png?alt=media&#x26;token=b030f7fe-8630-4030-a5ee-740b2ea08f19" alt="" width="528"><figcaption></figcaption></figure></div>

Alternatively, you can toggle the manual input option to ON and add syntax for [dynamic variables](https://doc.wearepatchworks.com/product-documentation/~/changes/J8IbZkP6ASUZu2oBhGi2/process-flows/building-process-flows/dynamic-variables):

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F0XIa97EntVBrZNuUxRo9%2Froute%20filter%20-%20manual%20input%201.png?alt=media&#x26;token=68c0d72b-9e30-4120-b871-2b61161037ad" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
The manual data path field supports [metadata variables](https://doc.wearepatchworks.com/product-documentation/~/changes/J8IbZkP6ASUZu2oBhGi2/process-flows/building-process-flows/dynamic-variables/metadata-variables).
{% endhint %}

**Step 8**\
Use remaining **operator**, **type** and **value** options to define the required filter.&#x20;

{% hint style="info" %}
Presentation of the **value** field is dependent upon your selected **type**. When defining a **value**, you can include [payload](https://doc.wearepatchworks.com/product-documentation/~/changes/J8IbZkP6ASUZu2oBhGi2/process-flows/building-process-flows/dynamic-variables/payload-variables), [flow](https://doc.wearepatchworks.com/product-documentation/~/changes/J8IbZkP6ASUZu2oBhGi2/process-flows/building-process-flows/dynamic-variables/flow-variables), and [metadata](https://doc.wearepatchworks.com/product-documentation/~/changes/J8IbZkP6ASUZu2oBhGi2/process-flows/building-process-flows/dynamic-variables/metadata-variables) variables. &#x20;
{% endhint %}

{% hint style="info" %}
When a string filter **type** is selected, you have the option to select the **regex** operator and then define a regex value. This provides greater flexibility if you can't achieve the desired results using standard operators. `preg_match` is used for pattern matching.
{% endhint %}

The following data types are available when defining filters:

<table><thead><tr><th width="224">Variable type</th><th>Variable is defined and passed as...</th></tr></thead><tbody><tr><td>String</td><td>A string value.</td></tr><tr><td>Number</td><td>A numeric value.</td></tr><tr><td>Specific date</td><td>A selected date - choose the required date/time from a date picker.</td></tr><tr><td>Dynamic date</td><td>A <code>+</code>/<code>-</code> number of <code>seconds</code>, <code>minutes</code>, <code>hours</code>, <code>days</code>, <code>months</code>, <code>years</code> to be matched relative to the current date.</td></tr><tr><td>Boolean</td><td>A true/false value.</td></tr></tbody></table>

**Step 9**\
Use the **keep matching?** toggle option to choose how matched records should be treated:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fj4mol1D95soGHAwUoAMs%2Froute%20filters%206.png?alt=media&#x26;token=7402c9a4-e42e-43bc-a2f7-4e4604ee84de" alt="" width="533"><figcaption></figcaption></figure></div>

Here:

* If the **keep matching?** option is toggled OFF, matched records are removed from the payload before it moves on down the flow for further processing.
* If the **keep matching?** option is toggled ON, matched records remain in the onward payload, and all non-matching records will be removed.

**Step 10**\
Click the **save** button (at the bottom of the panel) to confirm these settings. The new rule is added for your first route - 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%2FFkaATAofM8qigwYppQoy%2Froute%20filters%207.png?alt=media&#x26;token=92b2c0aa-8139-4ec6-bf38-1608ffef50e9" alt="" width="531"><figcaption></figcaption></figure></div>

**Step 11**\
Repeat steps 6 to 10 to add any additional rules for this route. When you've added all required rules, click the **save**/**update** button at the bottom of the panel.

**Step 12**\
Repeat steps 3 to 11 to configure the second route.

**Step 13**\
Add any additional routes required using the **add route** button. Each time you add a new route, the canvas updates with an additional route stem from your route shape.

**Step 14**\
Save your changes.

## What next?

Having defined all required routes and associated conditions, the **route** shape on the canvas will have the corresponding number of route stems, ready for you to add shapes. 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%2FZVK8DauXK6qV5jy5SvKU%2F3%20routes.png?alt=media&#x26;token=1a9eaa18-677f-4aa1-a840-b9ddf46866c6" alt="" width="310"><figcaption></figcaption></figure></div>

Click the + sign for each branch in turn, then add the required shapes for each route flow.


---

# 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/~/changes/J8IbZkP6ASUZu2oBhGi2/process-flows/building-process-flows/process-flow-shapes/standard-shapes/route-shape.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.
