Skip to main content

Dynamic

The Dynamic task is used to execute a registered task dynamically at run-time. It is similar to a function pointer in programming, and can be used for when the decision to execute which task will only be made after the workflow has begun.

The Dynamic task accepts as input the name of a task, which can be a system task or a custom task registered on Conductor.

Task parameters

Configure these parameters for the Dynamic task.

ParameterDescriptionRequired/ Optional
dynamicTaskNameParamThe input parameter key whose value is used to schedule the task. For example, "taskToExecute", which will then be specified as an input parameter in the Dynamic task.Required.
inputParameters. taskToExecuteThe name of the task that will be executed. It can be passed as a variable.Required.

Configuration for calling a sub-workflow

If the Dynamic task to be called is a Sub Workflow task, then taskToExecute must be set to SUB_WORKFLOW. The inputParameters for the Dynamic task should also include these fields:

// Dynamic task defintion

"inputParameters": {
"subWorkflowDefinition":{ //subworkflow JSON definition}
}

Task configuration

This is the task configuration for a Dynamic task.

{
"name": "dynamic",
"taskReferenceName": "dynamic_ref",
"inputParameters": {
"taskToExecute": "${workflow.input.dynamicTaskName}" // name of the task to execute
},
"type": "DYNAMIC",
"dynamicTaskNameParam": "taskToExecute" // input parameter key that will hold the task name to execute
}

Task output

During execution, the Dynamic task is replaced with whatever task that is called at runtime. The output of the Dynamic task will be whatever the output of the called task is.

Adding a Dynamic task in UI

To add a Dynamic task:

  1. In your workflow, select the (+) icon and add a Dynamic task.
  2. In Task input params, configure the task to execute by setting a value in the taskToExecute parameter. The value can be passed as a variable (for example, ${workflow.input.dynamicTaskName}).

Screenshot of Dynamic Task in Orkes Platform

Examples

Here are some examples for using the Dynamic task.

Using the Dynamic task in a workflow

In this example workflow, shipments are made with different couriers depending on the shipping address. The decision can only be made during run-time when the address is received, and the subsequent shipping task could be either ship_via_fedex and ship_via_ups. A Dynamic task can be used in this workflow so that the shipping task can be decided in realtime.

// workflow definition

{
"name": "Shipping_Flow",
"description": "Ships smartly based on the shipping address",
"tasks": [
{
"name": "shipping_info",
"taskReferenceName": "shipping_info_ref",
"inputParameters": {
},
"type": "SIMPLE"
},
{
"name": "shipping_task",
"taskReferenceName": "shipping_task_ref",
"inputParameters": {
"taskToExecute": "${shipping_info.output.shipping_service}"
},
"type": "DYNAMIC",
"dynamicTaskNameParam": "taskToExecute"
}
]
}

In the workflow, the shipping_info task generates an output that is used to determine which task is run in the Dynamic shipping_task task. The line "taskToExecute": "${shipping_info.output.shipping_service}" reads the shipping_service output from shipping_info. Here is the visual diagram of the same workflow:

Dynamic Task Example

During workflow execution, if the shipping_info task output is "shipping_service": "ship_via_fedex", the Dynamic shipping_task task will be replaced with the ship_via_fedex task:

Ship Via Fedex

If the shipping_info task output is "shipping_service": "ship_via_ups", the Dynamic shipping_task task will be replaced with the ship_via_ups task:

Ship Via UPS