Skip to main content

Set Variable

The Set Variable task allows you to create or update workflow-level variables. Use this task to define shared variables at the workflow level that can be accessed or overwritten by subsequent tasks in the workflow.

Variables can be initialized or updated at any point during workflow execution. If a variable with the same name is set again, the new value overwrites the existing value.

Task parameters

Configure these parameters for the Set Variable task.

ParameterDescriptionRequired/ Optional
inputParametersDefines one or more workflow-level variables as key-value pairs. Each key represents the variable name, and the corresponding value is the variable value to be set. Can be a string, number, boolean, null, or object/array.

Values can be hard-coded in the workflow definition or passed as a dynamic variable.
Required.

Once a variable is initialized, it can be accessed in any subsequent task using the expression ${workflow.variables.variableName}.

Note

The scope of the Set Variable task is limited to its workflow. An initialized variable in one workflow will not carry over to another workflow or sub-workflow and will have to be initialized again using a new Set Variable task. In some cases, you can consider setting up global environment variables to manage frequently accessed variables across workflows.

The following are generic configuration parameters that can be applied to the task and are not specific to the Set Variable 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.

Task configuration

This is the task configuration for a Set Variable task.

{
"name": "set_variable",
"taskReferenceName": "set_variable_ref",
"type": "SET_VARIABLE",
"inputParameters": {
"variableName": "value"
}
}

Adding a Set Variable task in UI

To add a Set Variable task:

  1. In your workflow, select the (+) icon and add a Set Variable task.
  2. In Variables, add the desired workflow variables that will be initialized or replaced with a new value.
  3. For each workflow variable, configure the following:
    • Key—The variable name.
    • Value—The variable value, which can be a dynamic input (for example, ${workflow.input.someKey}) or a fixed value.

Screenshot of Set Variable Task in Orkes Conductor

Examples

Here are some examples for using the Set Variable task.

Using the Set Variable task in a workflow

In this example, the workflow accepts an orderId as input. The Set Variable task stores the value as a workflow-level variable, which is then reused in multiple HTTP tasks without repeating the original expression.

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": "Reuse_Order_Id_With_Echo",
"description": "Store an order ID as a workflow variable and reuse it",
"version": 1,
"tasks": [
{
"name": "set_order_id",
"taskReferenceName": "set_order_id_ref",
"inputParameters": {
"orderId": "${workflow.input.orderId}"
},
"type": "SET_VARIABLE"
},
{
"name": "echo_order_id_get",
"taskReferenceName": "echo_order_id_get_ref",
"inputParameters": {
"method": "GET",
"uri": "https://postman-echo.com/get?orderId=${workflow.variables.orderId}",
"encode": true
},
"type": "HTTP"
},
{
"name": "echo_order_id_post",
"taskReferenceName": "echo_order_id_post_ref",
"inputParameters": {
"method": "POST",
"uri": "https://postman-echo.com/post",
"headers": {
"Content-Type": "application/json"
},
"body": {
"orderId": "${workflow.variables.orderId}"
}
},
"type": "HTTP"
}
],
"inputParameters": [
"orderId"
],
"schemaVersion": 2
}
  1. Select Save > Confirm.

To run the workflow:

  1. Go to the Run tab, and enter the Input params. For example:
{
"orderId": "ORD-1001"
}
  1. Select Execute.

Once the workflow completes, verify that the variable was reused:

  • Open the echo_order_id_get_ref task output and confirm that the response contains args.orderId: "ORD-1001":

Task output verifying that the variable was passed.

  • Open the echo_order_id_post_ref task output and confirm that the response body contains json.orderId: "ORD-1001":

Task output verifying that the variable was passed.

This confirms that the orderId value was stored once using the Set Variable task and reused across multiple downstream tasks using ${workflow.variables.orderId}.