# Subpipelines

{% hint style="info" %}
To access the subpipelines and use the features presented in this article, you need the permission PIPELINE:CREATE. Learn more in the[ documentation about Roles](/documentation/developer-guide/platform-administration/administration/new-access-control/access-control-roles.md).
{% endhint %}

Subpipelines are subflows of the pipeline that are connected and triggered by a component of the main flow, for example, [**For Each**](/documentation/connectors-and-triggers/connectors/logic/for-each.md).

Imagine a process called "Validation of Client Data". This process receives client data through the REST endpoint and then verifies that each client record contains the required data.

To iterate through the collection of records, we'll use the **For Each (Processes clients records)** component.

<figure><img src="/files/CrORMcixw0L4YCyRteAi" alt=""><figcaption></figcaption></figure>

Each time a component that can iterate through collections is added to a pipeline, 2 subpipelines are created: **OnProcess** and **OnException**.

## **OnProcess** <a href="#onprocess" id="onprocess"></a>

This subpipeline implements the subflow that processes each element in the collection. The **OnProcess** can be accessed from the component's menu:

<figure><img src="/files/mzucjBgVxvpUIWVB1255" alt=""><figcaption></figcaption></figure>

In the case of the "Validation of Client Data" process, the **OnProcess** subpipeline handles all the records of the clients collection individually and checks whether the "Date of birth" attribute is filled in each of them:

<figure><img src="/files/lkIC6TNUnVMP3oseuCm7" alt=""><figcaption></figcaption></figure>

At the end of each execution of the **onProcess** subpipeline, a success attribute is returned indicating whether the execution succeeded or failed. By default, this attribute is returned with a value "false". Thus, you must explicitly indicate when the execution went as expected.

In the "Validation of Client Data" process, the following success message is returned by the **JSON Generator (Success)** component when the "Date of birth" attribute is filled in:

```
{"success": true}
```

If the "Date of birth" attribute is empty, the **JSON Generator (Failure)** component returns the attribute with the value `"false"`:

```
{"success": false}
```

In this case, an exception is generated via the **Assert (Internal Error)** component:

<figure><img src="/files/OS9V9gxC3OilkcvJ5M7x" alt=""><figcaption></figcaption></figure>

The **Fail On Error** attribute indicates that execution of the pipeline flow will be interrupted and an exception will be thrown if the Assert component condition is not validated.

{% hint style="info" %}
If the exception is thrown by a component of a subpipeline, the execution of the **OnException** subpipeline is started. On the other hand, if the exception is thrown by a component in the main flow, the error causes the execution to stop.
{% endhint %}

## **OnException** <a href="#onexception" id="onexception"></a>

This subpipeline implements the flow that handles an exception to the execution of the **OnProcess** subpipeline. The **OnException** can be accessed from the component's menu:

<figure><img src="/files/QEACwjTW3uRKNHmbSoD8" alt=""><figcaption></figcaption></figure>

When the **OnException** is executed in the “Validation of Client Data” process, a request is made to a REST endpoint that records the incident and generates an error message in the [Pipeline logs](/documentation/developer-guide/development-cycle/dashboards/pipeline-logs.md) page.

<figure><img src="/files/WNLm0d3qMfLy5WiyWNkD" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The use of **OnException** is optional, but strongly recommended. Several Digibee Integration Platform components support the **Fail On Error** attribute and allow error handling and recovery strategies to be implemented through **OnException**, making the pipeline much more robust and resilient.
{% endhint %}

To learn more, read the [article Pipeline](/documentation/developer-guide/development-cycle/build-overview/pipelines.md).


---

# 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://docs.digibee.com/documentation/developer-guide/development-cycle/build-overview/pipelines/subpipelines.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.
