# Run a Subprocess

### Overview

One of the three ways a parent process can call a subprocess in Kognitos is by using the **Process Run Widget**. In this setup, the parent process controls the execution and output of the subprocess.

{% hint style="success" %}
This method is ideal for single-run scenarios where you need to capture the result and status of a subprocess.
{% endhint %}

### How to Call a Subprocess Using the Process Run Widget

1. In your automation, write the keyword <kbd>run</kbd> followed by a slash <kbd>/</kbd>
2. From the menu that appears, select **Process**.
3. Click on the Process drop-down menu to select the process you want to call.
4. Click **Save.**

<div data-with-frame="true"><figure><img src="https://681267560-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyXsMyN9vMn8AoQ4BYIwT%2Fuploads%2Fgit-blob-d04249f500f1fd10912c199efd45117002bf059b%2Fprocess-widget%20(1).gif?alt=media" alt=""><figcaption></figcaption></figure></div>

### Passing Data to a Subprocess

Passing data to a subprocess allows the parent process to provide the specific inputs the subprocess needs to do its work. This makes subprocesses more dynamic and reusable, as they don’t depend on hardcoded values. To enable this, the parent process must explicitly pass the required data, and the subprocess must be designed to accept and return values accordingly.

#### Parent Process

In your **parent process**, add a new line after `run <subprocess>`. Indent and reference the data needed for the subprocess run on the new line. If a data element is required but not explicitly provided, Kognitos will raise a [**question**](https://docs.kognitos.com/legacy/readme/core-concepts#question)**.**

#### Subprocess

In your **subprocess**, include one of these lines at the end of your automation to return data to the parent process. This syntax informs Kognitos of the subprocess's result so it can be accessed in the parent process.

* **For a single result:** `the result is {result}`
* **For multiple results:** `the results are {result 1}, {result 2}, ...`

### Examples

#### 1. Returning a Single Result

This example shows how a subprocess can be used to calculate a total. The main process, **Process an Invoice**, calls the subprocess **calculate the total** and provides the price. The subprocess uses the price to calculate and return the total.

{% tabs %}
{% tab title="Parent Process (Process an Invoice)" %}

```
run /calculate the total
    the price is $3
get the above as the total
```

{% endtab %}

{% tab title="Subprocess (calculate the total)" %}

```
the tax is $0.87
the total price is the price + the tax
the result is the total price
```

{% endtab %}
{% endtabs %}

<figure><img src="https://681267560-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyXsMyN9vMn8AoQ4BYIwT%2Fuploads%2Fgit-blob-d2bd63455f06aa8adc5b4056b42fe0f7c0dc45a7%2Frun-calculate-the-total-subprocess.gif?alt=media" alt=""><figcaption></figcaption></figure>

#### 2. Returning Multiple Results

This example shows how to return multiple results from a subprocess. Here, the subprocess **Split Full Name** returns two results: `the first name` and `the last name` .

{% tabs %}
{% tab title="Parent Process (Extracting Names)" %}

```
run /Split Full Name
  the full name is "Ada Lovelace"
get the above as the results
```

{% endtab %}

{% tab title="Subprocess (Split Full Name)" %}

```
split the full name into parts
get the first part as the first name
get the second part as the last name
the results are the first name, the last name
```

{% endtab %}
{% endtabs %}

<figure><img src="https://681267560-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyXsMyN9vMn8AoQ4BYIwT%2Fuploads%2Fgit-blob-ce6aa8413ea8203c01582c3d750ea95c3323c73b%2FRun%20Subprocess%20Get%20Multiple%20Results.gif?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
If you need to run **multiple instances** of a subprocess in parallel, see [Starting Parallel Runs](https://docs.kognitos.com/legacy/legacy-experience/writing-automations/calling-other-processes/start-parallel-runs) for details on using the `start a run` syntax.
{% endhint %}
