Set Variable
Set Variable
Section titled “Set Variable”Type: set-variable · Package: Core Activities v1.0.8
Assigns a value to a variable. It is the activity you use to create or update data by hand within the flow: initialize a counter, build up a text, store the result of a calculation, or change a variable’s value depending on what happens.
Unlike activities that store their result in an Output field, Set Variable exists precisely to assign a value that you define with an expression.
How it works
Section titled “How it works”You set the name of the target variable and the value. When it runs, it evaluates the value (a C# expression: a number, a quoted text, a variable or a calculation) and stores it in that variable, overwriting whatever it had.
- If the playbook declares variables (in the variables or arguments panel), the name must be one of them and the value must be compatible with its type; otherwise the activity fails (see Common errors).
- If the playbook declares no variables at all, the assignment creates the variable on the fly.
- It also gives a value to an output argument (Out or In/Out) of the playbook: that value is what the caller receives through Invoke Playbook.
- System variables (those starting with
$, such as$system_playbook_name) are read-only.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
name | string | — | Name of the variable to assign. A valid name (letters, digits and _, no spaces). It is a fixed name, not an expression. |
value | object | — | The value to store, as a C# expression: 0, "pending", total + 1… It can be of any type compatible with the variable. |
Optional parameters
Section titled “Optional parameters”None.
Output
Section titled “Output”This activity does not return a separate value: its result is the variable named in name itself.
Examples
Section titled “Examples”Initialize a counter and then increment it (a typical pattern inside a loop):
Set Variable name = counter value = 0...For Each items = invoices itemVariable = invoice └─ activities: Set Variable name = counter value = counter + 1Log message = "Invoices processed: " + counterAdd up a total:
Set Variable name = total value = total + num(row["Amount"])Build a flag from a condition:
Set Variable name = needsReview value = total > 1000000Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
Variable '…' is not declared. Declare it in the playbook's 'variables' section before using it. | The playbook declares variables and name is not one of them. Check the exact name (case-sensitive) or declare it in the variables panel. |
Variable '…': incompatible type. Declared as '…' but received '…'. | The value does not match the declared type (for example, a text in a numeric variable). Convert the value (num(...), str(...)) or change the variable’s type. |
System variable '…' is read-only and cannot be reassigned. | You tried to assign a system variable ($…). Copy its value into a variable of your own. |
'name' is required. | The target variable name is missing. |
| The Problems panel flags a name that does not exist | You typed fixed text without quotes (pending) and it was read as a variable. Put the text in quotes: "pending". |
Related activities
Section titled “Related activities”- Variables — how they are declared and their scope.
- Expressions — what you can calculate in
value.