SetVariable Activity
Purpose: Assign a value to a workflow variable. This activity allows you to set or update workflow variables during execution.
Input Properties
Variable
The workflow variable to assign the value to.
Type: Variable
Required: Yes
Note: Select or reference an existing workflow variable. The variable must be defined in the workflow.
Value
The value to assign to the variable.
Type: object
Default: null
Required: Yes
Note: Can be a literal value, expression, or reference to another variable. The type should match the variable's type.
Output Properties
This activity has no output properties.
Usage Example
Scenario: Set a counter variable to 0
Configuration:
- Variable: Select "Counter" (a workflow variable of type int)
- Value: "0" or "{{ 0 }}"
Result:
- The Counter variable is set to 0
- Subsequent activities can use this variable value
Scenario: Calculate and store a result
Configuration:
- Variable: Select "Result" (a workflow variable)
- Value: "{{ Variables.Input1 + Variables.Input2 }}"
Result:
- The Result variable is set to the sum of Input1 and Input2
- The calculated value is stored for use in later activities
Important Notes
- The variable must be defined in the workflow before it can be set
- The value type should match the variable type (or be convertible)
- Variables are scoped to the workflow instance and persist throughout execution
- You can set the same variable multiple times in a workflow
- Use expressions to calculate values dynamically
- For strongly-typed variables, use SetVariable<T> for better type safety
- Variables set in one activity are immediately available to subsequent activities