Skip to main content
All CollectionsBuild AutomationsOperators
Use Nested Workflows in Torq: Improve Modularity and Reusability
Use Nested Workflows in Torq: Improve Modularity and Reusability

Learn how to use nested workflows to improve your Torq workflows' efficiency, modularity, and scalability.

Updated over a week ago

Use the nested workflow operator to make complex workflows easier to read, more efficient, and simpler to maintain. It lets you break down big workflows into smaller, reusable parts (subroutines).

Important to Know

Nested workflows are triggered by the parent workflow and require the On-demand trigger. Set the Triggered from toggle:

  • Anywhere: The workflow can be triggered from the designer or external sources such as Slack, and is also available as a nested workflow. The workflow counts toward the workspace workflow quota.

  • Nested only: This workflow is just for use within other workflows. The workflow counts toward the workspace nested workflow quota.

A published parent workflow runs the published version of nested workflows (unless an ID of a different revision was specified). If the parent workflow is a draft, it uses the latest version of the nested workflow, whether it's published or still a draft.

Nested workflow executions generate an activity log entry with the parent workflow as the event source.

Create a Nested Workflow

To create a nested workflow, you can:

  • Create a workflow with an on-demand trigger. Then, incorporate it as a nested workflow by using the nested workflow operator in the parent workflow (see example below).

  • Select several steps and click the Create workflow icon to turn them into a nested workflow.

Edit a Nested Workflow

To test a draft version of a nested workflow, the parent workflow must also be in draft mode. If the parent workflow is published, it'll use the nested workflow's published version.

Here's what to do:

  1. Switch the parent workflow to draft mode.

  2. Make changes to the nested workflow.

  3. To test, manually start the parent or nested workflows.

View the List of Dependent Workflow

When you edit a workflow, first check which workflows depend on it to avoid issues. Here’s how:

  1. Click View Affected Workflows to see which workflows (parent workflows) might be impacted by your edits.

  2. If there are several layers of nested workflows, check each level similarly.

  3. Update any workflows that need changes because of your edits.

  4. Test the changes by running the workflows. If testing a draft version, ensure the parent workflow is also in draft mode.

  5. Once everything works, publish the updated workflows.

Execution Options

Here are some settings you can change for a nested workflow:

  • Ignore failure: By default, if a nested workflow fails, the parent workflow stops and shows a failure. If you choose Yes, the parent workflow will keep running even if there's a problem with the nested workflow.

  • Wait for output: By default, the parent workflow waits until the nested workflow is done to continue. If you select No, both workflows will run at the same time. However, the main workflow might not get the results from the nested workflow right away.

Example: How to Set Up and Use Nested Workflows

1. Creating a Nested Workflow:
A nested workflow is a regular workflow with an on-demand trigger. In this example, the nested workflow will enrich an IP address.

  1. On the Workflows page, click Create Workflow.

    1. Give the workflow a meaningful name, such as IP Enrichment.

    2. Select the On Demand trigger and click Create Workflow.

  2. Select the trigger to add input parameters for passing the required data from the parent workflow to the nested workflow. This example uses a short-text field titled IP Address as the workflow aims to enrich an IP address.

  3. Implement the logic to enrich the IP address. Access the IP address by using: {{ $.event.ip_address }}

  4. Add the Exit operator and define the workflow output. This output will be accessible in the parent workflow upon the completion of the nested workflow execution.

2. Using the Nested Workflow in a Parent Workflow:

The parent workflow executes the nested workflow as part of its logic, providing the necessary information and using the output in subsequent steps.

  1. Create the parent workflow and implement the required logic.

  2. Add the Workflow operator.

    1. Select a workflow to call as a nested workflow.

    2. Provide the values for the nested workflow input parameters.

  3. Access the nested workflow output in subsequent steps by using: {{ $.<nested_workflow_name>.<output_structure> }}

Did this answer your question?