Skip to content

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.

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.
ParameterTypeDefaultDescription
namestring—Name of the variable to assign. A valid name (letters, digits and _, no spaces). It is a fixed name, not an expression.
valueobject—The value to store, as a C# expression: 0, "pending", total + 1… It can be of any type compatible with the variable.

None.

This activity does not return a separate value: its result is the variable named in name itself.

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 + 1
Log message = "Invoices processed: " + counter

Add up a total:

Set Variable name = total value = total + num(row["Amount"])

Build a flag from a condition:

Set Variable name = needsReview value = total > 1000000
MessageCause 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 existYou typed fixed text without quotes (pending) and it was read as a variable. Put the text in quotes: "pending".
  • Variables — how they are declared and their scope.
  • Expressions — what you can calculate in value.