# Execute Sub-workflow

Use the Execute Sub-workflow node to run a different workflow on the host machine that runs Automated Workflows.

## Node parameters

### Source

Select where the node should get the sub-workflow's information from:

- **Database**: Select this option to load the workflow from the database by ID. You must also enter either:
  - **From list**: Select the workflow from a list of workflows available to your account.
  - **Workflow ID**: Enter the ID for the workflow. The URL of the workflow contains the ID after `/workflow/`. For example, if the URL of a workflow is `https://my-ts-wf-acct.app.ts-wf.cloud/workflow/abCDE1f6gHiJKL7`, the **Workflow ID** is `abCDE1f6gHiJKL7`.
- **Local File**: Select this option to load the workflow from a locally saved JSON file. You must also enter:
  - **Workflow Path**: Enter the path to the local JSON workflow file you want the node to execute.
- **Parameter**: Select this option to load the workflow from a parameter. You must also enter:
  - **Workflow JSON**: Enter the JSON code you want the node to execute.
- **URL**: Select this option to load the workflow from a URL. You must also enter:
  - **Workflow URL**: Enter the URL you want to load the workflow from.


### Workflow Inputs

If you select a sub-workflow using the **database** and **From list** options, the sub-workflow's input items will automatically display, ready for you to fill in or map values.

You can optionally remove requested input items, in which case the sub-workflow receives `null` as the item's value. You can also enable **Attempt to convert types** to try to automatically convert data to the sub-workflow item's requested type.

Input items won't appear if the sub-workflow's Workflow Input Trigger node uses the "Accept all data" input data mode.

### Mode

Use this parameter to control the execution mode for the node. Choose from these options:

- **Run once with all items**: Pass all input items into a single execution of the node.
- **Run once for each item**: Execute the node once for each input item in turn.


## Node options

This node includes one option: **Wait for Sub-Workflow Completion**. This lets you control whether the main workflow should wait for the sub-workflow's completion before moving on to the next step (turned on) or whether the main workflow should continue without waiting (turned off).

## Set up and use a sub-workflow

This section walks through setting up both the parent workflow and sub-workflow.

### Create the sub-workflow

1. Create a new workflow.


### Create sub-workflows from existing workflows

- You can optionally create a sub-workflow directly from an existing parent workflow using the **Execute Sub-workflow** node.
  - In the node, select the **Database** and **From list** options and choose **Create a sub-workflow** from the list.
- You can also extract selected nodes using **Sub-workflow conversion** from the context menu.


### Optional: Configure which workflows can call the sub-workflow

1. Open the **Options** menu > **Settings**.
2. In the **Workflow settings** modal, change the **This workflow can be called by** setting.
  - Refer to *Workflow settings* documentation for more details.
3. Add the **Execute Sub-workflow Trigger** node (also listed as *When Executed by Another Workflow* under trigger nodes).
4. Set the **Input data mode** to choose how the sub-workflow will accept input data:
  - **Define using fields below**: Define individual input names and types that the calling workflow will provide. These will auto-populate in the calling node.
  - **Define using JSON example**: Provide an example JSON object to illustrate expected input.
  - **Accept all data**: Accept all incoming data without defining input items. The workflow must handle missing or inconsistent data internally.
5. Add additional nodes to build your sub-workflow logic.
6. Save the sub-workflow.


Info
**Sub-workflow must not contain errors:** If there are errors, the parent workflow won't be able to trigger it.

### Call the sub-workflow

1. Open the workflow where you want to call the sub-workflow.
2. Add an **Execute Sub-workflow** node.
3. In the node configuration, set the sub-workflow to call. You can:
  - Use the workflow **ID**,
  - Load from a **local file**,
  - Add **JSON definition** as a parameter,
  - Or call the workflow by **URL**.
**Find your workflow ID:** It's the alphanumeric string at the end of the sub-workflow’s URL.
4. Provide the required input items defined by the sub-workflow.
5. Save the parent workflow.


When executed, it will send data to the sub-workflow and run it. You can trace execution:

- In the **Execute Sub-workflow** node, click **View sub-execution**.
- In the sub-workflow, you’ll find a link back to the parent workflow.


### How data passes between workflows

Example:

- Workflow A contains an **Execute Sub-workflow** node that calls Workflow B.
- The **Execute Sub-workflow** node in A passes data to the **Execute Sub-workflow Trigger** in B (titled *When executed by another node*).
- The last node in Workflow B returns the result back to the calling node in Workflow A.