Skip to main content

Dynamic

The dynamic task allows us to execute one of the registered tasks dynamically at run-time. This means that you can run a task not fixed at the time of the workflow’s execution. The task name could even be supplied as part of the workflow’s input and be mapped to the dynamic task input.

Definitions

    {
"name": "dynamic_task",
"taskReferenceName": "dynamic_task_ref",
"inputParameters": {
"taskToExecute": "${workflow.input.somevalue}" // Name of the task to execute
},
"type": "DYNAMIC",
"dynamicTaskNameParam": "taskToExecute" // Name of the input parameter holding the task name to execute
}

Input Parameters

AttributeDescription
taskToExecuteAccepts the task name to execute.
dynamicTaskNameParamIndicates the name of the task to be called during workflow execution.

If there is a possibility that the task called is a sub-workflow, then the parameter taskToExecute must be “SUB_WORKFLOW”.

And the input parameter should be either:

{
"subWorkflowDefinition":{...}
}

Or

{
"subWorkflowName":"...",
"subworkflowVersion":1
}

An example where a sub-workflow is added in a dynamic task:

{
"name": "dynamic_task",
"taskReferenceName": "ref_name",
"inputParameters": {
"taskToExecute": "SUB_WORKFLOW",
"subWorkflowName": "workflow_name_here",
"subWorkflowVersion": 1
},
"type": "DYNAMIC",
}

Output Parameters

During execution, the DYNAMIC task is replaced in the workflow with whatever task is called dynamically. The output during execution is whatever the output of the called task.

Examples



  1. Add task type Dynamic Task.
  2. Add the task to run by mapping it to a variable representing task name.

Adding wait task

Shipping Courier

Suppose in a workflow, we have to decide to ship the courier, but the decision is to be made during execution. The workflow looks like this:

{
"name": "Shipping_Flow",
"description": "Ships smartly on the basis of Shipping info",
"tasks": [
{
"name": "shipping_info",
"taskReferenceName": "shipping_info",
"inputParameters": {
},
"type": "SIMPLE"
},
{
"name": "shipping_task",
"taskReferenceName": "shipping_task",
"inputParameters": {
"taskToExecute": "${shipping_info.output.shipping_service}"
},
"type": "DYNAMIC",
"dynamicTaskNameParam": "taskToExecute"
}
]
}

The shipping_info task generates an output that is used to determine which task is run in the shipping_task DYNAMIC task. The line "taskToExecute": "${shipping_info.output.shipping_service}" reads the shipping_service output from shipping_info. In this example, there are two possible outputs, ship_via_fedex or ship_via_ups.

Here is the workflow with the DYNAMIC task:

Dynamic Task Example

Now, assume a workflow execution where shipping_info outputs:

{
"shipping_service": "ship_via_fedex"
}

The DYNAMIC task shipping_task has been replaced with ship_via_fedex:

Ship Via Fedex

If the output is:

{
"shipping_service": "ship_via_ups"
}

The DYNAMIC task shipping_task has been replaced with ship_via_ups:

Ship Via UPS