# Subprocesses

## What is a subprocess <a href="#podprocesy-utworzeniepodprocesu" id="podprocesy-utworzeniepodprocesu"></a>

**Workflow subprocess** (eng. *subprocess*) is a separate fragment of a larger business process that performs a specific, repeatable set of actions. It is used to organize and modularly design workflows – this allows complex processes to be broken down into smaller, easier-to-manage parts.

Subprocesses make it easier to reuse the same procedures in different parts of the system, increase the clarity of BPMN diagrams, and enable independent testing and modification of individual process stages. As a result, the organization gains greater flexibility, consistency, and ease of maintaining its business processes.

## Working with subprocesses <a href="#podprocesy-utworzeniepodprocesu" id="podprocesy-utworzeniepodprocesu"></a>

### Creating a subprocess <a href="#podprocesy-utworzeniepodprocesu" id="podprocesy-utworzeniepodprocesu"></a>

We create and save a subprocess in the same way as a process.

### Adding a subprocess to a process <a href="#podprocesy-dodaniepodprocesudoprocesu" id="podprocesy-dodaniepodprocesudoprocesu"></a>

When editing the process to which we want to add a previously created subprocess, in the main process we add an element of the type **Task**.

Then we change its type to **Call Activity** (context menu **Change element** will be displayed after selecting the block and clicking the key icon).

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FYFChiCtBTJZkRcHxQzhG%2Fimage.png?alt=media&#x26;token=8a222fe1-3e04-4f95-9aaa-2eb1724ae1df" alt=""><figcaption><p><em><strong>Figure 1.</strong> Task type change menu</em></p></figcaption></figure>

In the next step, for the selected block **Call Activity** in the right panel we expand the section **Called element**. First, we set the element type (property **Type**) to **BPMN**, and after expanding the next fields, we enter in the field **Called element** the process created earlier - placing it as a subprocess in the edited process.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FyrUvN4cdaWrsamUk4ito%2Fimage.png?alt=media&#x26;token=78182aac-fc32-4c7d-a537-4c58bdbd11fa" alt=""><figcaption><p><em><strong>Figure 2.</strong> "Call Activity" menu</em></p></figcaption></figure>

### Subprocesses and dependencies

Since a subprocess is part of another process, when saving the process definition in the version save window, we will receive information about dependent artifacts.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FPIcVqwJC3n7yZRCYEdCf%2Fimage.png?alt=media&#x26;token=565091e8-60ce-4249-8021-ac6a3e26ca89" alt=""><figcaption></figcaption></figure>

Due to this dependency, it is not possible to delete the subprocess definition from the repository.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FlnMbRpsd9f6r2x8JOGp9%2Fimage.png?alt=media&#x26;token=c5dec6d2-8159-46dc-b4d9-b4340633a203" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Deleting the main process is possible and is not confirmed by any dialog. However, a message appears at the bottom of the screen allowing you to undo this operation.
{% endhint %}

When downloading the process artifact that is the main process (option **Download** in the context menu of the given process), the subprocess of this process will also be downloaded.

```xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<exportArtifactWithDependencies>
    <dependencies>
        <dependency>
            <additionalData></additionalData>              
            <content>PD94bXZlbnQ{...}XRpb25zPgo=</content>
            <folderPath>/developers/mwachowska/</folderPath>
            <majorVersion>1</majorVersion>
            <minorVersion>6</minorVersion>
            <name>podproces.bpmn</name>
            <type>bpmn</type>
        </dependency>
    </dependencies>
    <exportArtifact>
        <additionalData></additionalData>
        <content>PD94bW{...}lvbnM+Cg==</content>
        <folderPath>/developers/mwachowska/</folderPath>
        <majorVersion>1</majorVersion>
        <minorVersion>3</minorVersion>
        <name>proces_glowny.bpmn</name>
        <type>bpmn</type>
    </exportArtifact>
</exportArtifactWithDependencies>
```

When importing into the process application a process with subprocesses, they will also be automatically added to that application

### Versioning and use of subprocesses

In the field **Binding** we can specify the version of the subprocess.

* By default, latest is set, meaning always the newest version.
* However, we can indicate a specific version (version) or bind the subprocess version to the deployment of the main process (deployment).

The same subprocess **can be used in many main processes**, therefore its update may affect all related processes. After testing and before production deployment, it is recommended to bind it to a specific stable version.

Open instances always use the version of the subprocess that existed when the main process was started. New instances, if Binding = latest, will use the new version of the subprocess.
