For the complete documentation index, see llms.txt. This page is also available as Markdown.

Dispatch Workflow Activity

The Dispatch Workflow activity can start a new workflow from the current workflow.

It allows you to specify what workflow to run and provide any input required by the workflow.

If you need to fan out one child workflow per item in a collection, use Bulk Dispatch Workflows Activity instead.

Let's try it out.

Using Code

The following code listings show two workflows:

  1. The parent workflow

  2. The child workflow to dispatch

ParentWorkflow.cs
using Elsa.Workflows;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Runtime.Activities;

public class ParentWorkflow : WorkflowBase
{
    protected override void Build(IWorkflowBuilder builder)
    {
        var childOutput = builder.WithVariable<IDictionary<string, object>>();

        builder.Root = new Sequence
        {
            Activities =
            {
                new DispatchWorkflow
                {
                    WorkflowDefinitionId = new(nameof(ChildWorkflow)),
                    Input = new(new Dictionary<string, object>
                    {
                        ["ParentMessage"] = "Hello from parent!"
                    }),
                    WaitForCompletion = new(true),
                    Result = new(childOutput)
                },
                new WriteLine(context => $"Child finished executing and said: {childOutput.Get(context)!["ChildMessage"]}")
            }
        };
    }
}

Using Elsa Studio

The following recorded guides demonstrate how to create a child workflow and a parent workflow that then dispatches the child workflow for execution.

Last updated