Set Variable
The Set Variable task allows you to create or update workflow-level variables. The task is used to construct a shared variable at the workflow level across tasks, and these variables can be accessed or overwritten in any subsequent task in the workflow.
Variables can be initialized and updated at any point in the workflow. Once a variable is initialized, it can be accessed in any subsequent task using the expression ${workflow.variables.variableNameHere}
(replacing variableNameHere with the actual variable name). Initialized values can be overwritten by a subsequent Set Variable task.
Task parameters
To configure the Set Variable task, set your desired variables and their respective values in inputParameters
. The values can be set in two ways:
- Hard-coded in the workflow definition, or
- A variable input that is defined in real-time during workflow execution.
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:
- In your workflow, select the (+) icon and add a Set Variable task.
- In Variables, add the desired workflow variables that will be initialized or replaced with a new value.
- For each workflow variable, configure the following:
- Type—the variable type, which can be a string, number, boolean, null, or object/array.
- Key—the variable name.
- Value—the variable value, which can be a variable input (for example,
${workflow.input.someKey}
) or a hard-coded value.
Examples
Here are some examples for using the Set Variable task.
Using the Set Variable task in a workflow
In this example workflow, a username is stored as a variable so that it can be reused in other tasks that require the username.
// workflow definition
{
"name": "Welcome_User_Workflow",
"description": "Designate a user to be welcomed",
"tasks": [
{
"name": "set_name",
"taskReferenceName": "set_name_ref",
"type": "SET_VARIABLE",
"inputParameters": {
"name": "${workflow.input.userName}"
}
},
{
"name": "greet_user",
"taskReferenceName": "greet_user_ref",
"inputParameters": {
"var_name" : "${workflow.variables.name}"
},
"type": "SIMPLE"
},
{
"name": "send_reminder_email",
"taskReferenceName": "send_reminder_email_ref",
"inputParameters": {
"var_name" : "${workflow.variables.name}"
},
"type": "SIMPLE"
}
]
}
In the example above, set_name
is a Set Variable task that takes a variable input for name
. In subsequent tasks, the name
is later referenced using ${workflow.variables.name}
.
Limitations
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.