Skip to content

SubWorkflow

The SubWorkflow module allows executing another workflow as a sub-process within the current flow. It supports three execution modes: synchronous (waits for the result before continuing), asynchronous (launches and continues without waiting), and parallel (executes multiple instances if the input is an array). It can inherit the parent workflow state (workflowState) to share context between flows. Each execution generates a child instance with complete traceability, recording the parent-child relationship in the database. It is ideal for reusing workflow logic, splitting complex flows into manageable sub-processes, or executing batch operations.

ParameterTypeRequiredDescription
workflow_idworkflow_selectorYesSelects the workflow to be executed as a sub-process.
execution_modeselectYesExecution mode: sync (wait for result), async (fire & forget), parallel (multiple instances). Default: sync.
pass_statebooleanNoPasses the current workflowState to the sub-workflow. Default: true.
input_datacode_editorNoJSON data or variables to send as input to the sub-workflow. Supports dynamic variables.
timeout_msnumberNoMaximum wait time in synchronous mode (0 = no limit). Default: 30000.
{
"nextModule": "siguiente_modulo",
"data": {
"resultado_del_subworkflow": "valor"
}
}
{
"nextModule": "siguiente_modulo",
"data": {
"child_instance_id": "sub_workflow123_abc123",
"workflow_id": 456,
"workflow_name": "Proceso de envio",
"status": "launched",
"message": "Sub-workflow lanzado en modo asincronico"
}
}
{
"nextModule": "siguiente_modulo",
"data": {
"mode": "parallel",
"total": 3,
"success_count": 2,
"error_count": 1,
"results": [
{ "index": 0, "success": true, "instance_id": "sub_wf_abc_0", "data": {} },
{ "index": 1, "success": true, "instance_id": "sub_wf_abc_1", "data": {} }
],
"errors": [
{ "index": 2, "success": false, "instance_id": "sub_wf_abc_2", "error": "mensaje" }
]
}
}
{
"label": "Sub Workflow",
"workflow_id": "123",
"execution_mode": "sync",
"pass_state": true,
"input_data": "",
"timeout_ms": 30000
}
  • In sync mode, the parent flow waits for the sub-workflow to finish before continuing.
  • In async mode, the parent flow continues immediately. The sub-workflow runs in the background with setImmediate.
  • In parallel mode, if the input is an array, one sub-workflow instance is launched per element. Concurrency is limited to 5 simultaneous instances by default.
  • If pass_state is true, the parent’s workflowState is inherited by the sub-workflow.
  • If input_data is empty, the current node’s input data is used.
  • Each child instance is registered in the workflowinstances table with a reference to the parent.
  • The state of each child instance is automatically updated (completed/failed).
  • If the specified workflow does not exist or does not belong to the same client, an error is returned.
  • Supports dynamic variables in input_data.
  • Iterator - alternative for parallel array processing
  • Decision - to decide which sub-workflow to execute
  • End - final node of the sub-workflow