Skip to main content

Dynamic

The Dynamic task executes a registered task dynamically at runtime. It is similar to a function pointer in programming and can be used in cases where the decision to execute a task will only be made after the workflow has begun. Unlike the Switch task, the Dynamic task offers flexibility without requiring updates to the workflow definition.

The Dynamic task accepts as input the name of a task, which can be a system task, a sub-workflow, or a custom Worker 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 dynamic variable.Required.
inputParametersContains the inputs to the task that will be executed.Required, depending on the task.

The following are generic configuration parameters that can be applied to the task and are not specific to the Dynamic task.

Other generic parameters

Here are other parameters for configuring the task behavior.

ParameterDescriptionRequired/ Optional
optionalWhether the task is optional.

If set totrue, any task failure is ignored, and the workflow continues with the task status updated to COMPLETED_WITH_ERRORS. However, the task must reach a terminal state. If the task remains incomplete, the workflow waits until it reaches a terminal state before proceeding.
Optional.

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": {
"subWorkflowName":"someName",
"subworkflowVersion": "1"
}

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, specify the task to execute by setting a value in the taskToExecute parameter. The value can be passed as a dynamic variable (for example, ${workflow.input.dynamicTaskName}).

Screenshot of Dynamic Task in Orkes Conductor

Examples

Here are some examples for using the Dynamic task.

Using the Dynamic task in a workflow

A Dynamic task executes a task type at runtime based on an input value. This example builds a workflow that dynamically executes the HTTP system task.

To create a workflow:

  1. Go to Definitions > Workflow, from the left navigation menu on your Conductor cluster.
  2. Select + Define workflow.
  3. In the Code tab, paste the following workflow definition:
{
"name": "Dynamic_HTTP_Demo",
"description": "Dynamically executes the HTTP system task using a Dynamic task.",
"version": 1,
"schemaVersion": 2,
"inputParameters": [
"taskType"
],
"tasks": [
{
"name": "dynamic_http_task",
"taskReferenceName": "dynamic_http_task_ref",
"type": "DYNAMIC",
"inputParameters": {
"taskToExecute": "${workflow.input.taskType}",
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"encode": true
},
"dynamicTaskNameParam": "taskToExecute"
}
]
}
  1. Select Save > Confirm.

To run the workflow:

  1. Go to the Run tab, and enter the Input params. For example:
{
"taskType": "HTTP"
}
  1. Select Execute.

This takes you to the workflow execution page. You can verify that:

  • The Dynamic task is replaced at runtime with the HTTP task.
  • The HTTP task completes successfully.
  • The task output contains the HTTP response.

Task output of a Dynamic task

Using the Dynamic task to execute a sub-workflow

A Dynamic task can execute a sub-workflow at runtime when the sub-workflow name is determined after the workflow starts. This example builds a parent workflow that executes a sub-workflow dynamically using the SUB_WORKFLOW task type.

Before you begin, create the workflows to be called as Sub Workflows.

To create a workflow:

  1. Go to Definitions > Workflow, from the left navigation menu on your Conductor cluster.
  2. Select + Define workflow.
  3. In the Code tab, paste the following workflow definition:
{
"name": "ship_via_fedex",
"description": "Sub-workflow that simulates FedEx shipping.",
"version": 1,
"schemaVersion": 2,
"tasks": [
{
"name": "fedex_http",
"taskReferenceName": "fedex_http_ref",
"type": "HTTP",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"encode": true
}
}
]
}
  1. Select Save > Confirm.

Repeat the steps and create another workflow for UPS using the following code:

{
"name": "ship_via_ups",
"description": "Sub-workflow that simulates UPS shipping.",
"version": 1,
"schemaVersion": 2,
"tasks": [
{
"name": "ups_http",
"taskReferenceName": "ups_http_ref",
"type": "HTTP",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"encode": true
}
}
]
}

Next, create the parent workflow that includes a Dynamic task, which will call any of these workflows.

{
"name": "Dynamic_Subworkflow_Demo",
"description": "Dynamically executes a sub-workflow based on runtime input.",
"version": 1,
"schemaVersion": 2,
"inputParameters": [
"carrierWorkflow"
],
"tasks": [
{
"name": "dynamic_subworkflow",
"taskReferenceName": "dynamic_subworkflow_ref",
"type": "DYNAMIC",
"inputParameters": {
"taskToExecute": "SUB_WORKFLOW",
"subWorkflowName": "${workflow.input.carrierWorkflow}",
"subworkflowVersion": 1
},
"dynamicTaskNameParam": "taskToExecute"
}
]
}

In this workflow, the Dynamic task schedules a sub-workflow by setting taskToExecute to SUB_WORKFLOW and providing the sub-workflow name as input.

To run the workflow:

  1. Go to the Run tab, and enter the Input params. For example:
{
"carrierWorkflow": "ship_via_fedex"
}
  1. Select Execute.

This takes you to the workflow execution page. You can verify that:

  • The Dynamic task is replaced at runtime with a sub-workflow execution.
  • The executed sub-workflow name matches the value passed in carrierWorkflow.

Task output of a Dynamic task

  • The sub-workflow’s HTTP task completes successfully.

Task output of a HTTP task executed via Sub Workflow