# Run another workflow

Call one workflow from another as a step, and use what it returns.

Build a job once, such as “look up the customer”, and call it from every workflow that needs it.

```
Trigger New order (Webhook)
01 Look up the customer (Sub-flow)
02 Email the customer (Gmail)
```

**Look up the customer** runs another workflow, waits for it, and passes its result to step 02.

## Set up the workflow you call

1. In the workflow to call, press **Add a trigger** and choose **When Called by Another Workflow**.
2. In **Expected Input**, write a sample of what it receives, such as `{"email": "ada@acme.example"}`.
3. In its steps, use the input as `{{trigger.email}}`.
4. Press **Publish**.

The sample is the agreement between the two workflows: the calling step fills its **Input** from it, and a test of this workflow uses it.

## Call it

1. In the other workflow, add a step: type `sub-flow` and choose **Sub-flow**.
2. Under **Workflow**, choose the one to call.
3. In **Input**, put in your values, such as `{"email": "{{trigger.body.email}}"}`.

Later steps read what it returned: `{{steps.step_1.output}}` is its last step’s output, and `{{steps.step_1.steps}}` holds every step’s.

## What to know

- **It waits**: The step waits until the other workflow ends. There is no option to carry on without waiting.
- **Its version**: It runs the published version of the workflow you call, or its draft if it was never published.
- **If it fails**: The step fails too, with the reason, and the step’s **On error** decides what happens next.
- **Its own run**: On a run’s page, the step’s **Output** names the workflow it ran and shows what came back. **Open that run** shows every step inside it.
- **Time**: It must finish within both workflows’ time limits.
- **Depth**: Workflows can call each other 5 levels deep. A workflow that calls itself stops there.

> **Note** In a workflow you call, an approval fails, and a **Delay** longer than 5 minutes fails. Put waits in the calling workflow.

## Check it worked

Press **Test** in the calling workflow. The **Sub-flow** card shows Worked, and its **Result** shows what came back.

## For developers

The step is `pieceId: "subflow"`, `actionId: "execute"`, with `config.workflow_id` and `config.input`. The trigger is `callable` (`called_by_flow`). Its output also has `subRunId`, the id of the other workflow’s run. See [Workflow definition](https://docs.gorunner.io/api/workflow-definition).

## Related

- [Sub-flow](https://docs.gorunner.io/apps/sub-flow): Every field and output
- [Handle errors](https://docs.gorunner.io/build/handle-errors): What happens when the called workflow fails · 4 min
- [Use data from earlier steps](https://docs.gorunner.io/build/use-data-from-earlier-steps): Expressions and the Data pane · 5 min

Source: https://docs.gorunner.io/build/run-another-workflow
