Trigger workflow function

Learn more about the trigger workflow function within Knock's notification engine.
🚧
Trigger workflow function is currently in beta. If you'd like early access, or this is blocking your adoption of Knock, please get in touch.

A trigger workflow function enables you to invoke a workflow from within another workflow. This function allows you to compose complex notifications by reusing logic across multiple workflows, improving maintainability and reducing duplication.

When using the trigger workflow function, you can utilize the data passed directly from the parent workflow or specify custom data for use when triggering the nested workflow.

How trigger functions work

The trigger workflow step functions similarly to a standard workflow trigger, executing a specified workflow with a specified payload. The payload is constructed based on the configuration settings defined in the step.

Like other functions, the trigger workflow function runs independently for each recipient in the parent workflow. This means that if your parent workflow has three recipients, the trigger function will execute three times, creating distinct workflow runs each time. This behavior ensures that each recipient's context and data is properly isolated in the nested workflow.

Configuring a trigger function

Configure trigger workflow function settings

1

Select an active workflow

  • Choose from any currently active workflows in your system
2

Configure step settings for trigger data

  • Recipients
  • Actor (optional)
  • Tenant (optional)
  • Data (optional)
  • Cancellation key (optional)

Selecting the workflow

You can select any active workflow for use in the trigger workflow step. The trigger function will always use the most recently committed version of the selected workflow. To ensure that the correct workflow version is triggered, you must commit any intended changes to the selected workflow. Any uncommitted changes to the selected workflow will not be reflected when the step is executed.

If the selected workflow is later set to inactive or is archived, the trigger workflow step will be in an invalid state and the step will be skipped.

Setting the trigger data

The trigger workflow function uses strings or Liquid variables to define the trigger data for the nested workflow. You can reference any variables and data available in the parent workflow run.

FieldTypeDefault ValueDescription
recipientsstring{{ recipient.id }}The recipient(s) who will receive the nested workflow.
actorstring{{ actor.id }}The user or system initiating the nested workflow.
tenantstring{{ tenant.id }}The tenant context for the nested workflow.
datastring{{ data | json }}Data payload passed to the nested workflow.
cancellation_keystring{{ workflow.cancellation_key }}Unique identifier used to cancel nested workflow runs.

Handling Errors

When configuring the trigger workflow function, you may encounter the following errors:

  • Liquid Rendering Error: This occurs when there is a syntax error in the Liquid template used for defining trigger data. Ensure that all variables and expressions are correctly formatted and available in the parent workflow context.

  • Invalid Trigger Data: If the resolved trigger data for the nested workflow is invalid, the workflow execution will fail. This can happen if required fields are missing or contain incorrect values. Double-check the data being passed to ensure it meets the expected format and requirements of the nested workflow.

Workflow cancellation

When using trigger workflow functions, both parent and nested workflows can be canceled if they contain cancelable steps (batch, delay, or fetch functions) and are configured with cancellation keys.

If the parent workflow is canceled before the trigger workflow step executes, the nested workflow will not be triggered, so no separate cancellation is needed.

If you need to cancel a nested workflow that has already been triggered, you can do so by making a separate cancellation request using the cancellation key configured in the trigger workflow step. Canceling the parent workflow after the trigger workflow step has executed will not automatically cancel the nested workflow - you'll need to cancel each workflow separately.