DocsNodesDataSet variable

Set variable

Keeps a value. A local variable lives for this run only. A shared variable is one value for the whole workflow, kept between runs, so it can count things or remember the last state.

Kindcontrol:variable
GroupData
Credits0.1 credits
Ports out1

How it looks

Settings

SettingRequiredWhat it does
Keep it forscopeYesThis run (Local) or Every run (Shared). Shared variables are declared on the workflow with a type and a default.
VariablevarYesIts name. Names starting with __ are WBSKT's own.
DoopYesSet it to a value. A shared variable can also Compare and set, and a shared counter Increment and Decrement.
ValuevalueNoA fixed value, or one from the run.
Only if it is nowexpectedNoFor Compare and set: the value is written only if the variable holds this now.

Ports

PortThe run leaves by it when
defaultAfter the write.

What it adds to the run

Later nodes can read these, in a condition or as {{name}} in a text field.

ValueHolds
(the name)A local variable, by its name, for later nodes.
casSucceededFor Compare and set: whether the write happened.

Example

Count the doorbell rings today

  1. Declare a shared counter rings, default 0.
  2. In the doorbell workflow, Set variable: Every run, rings, Increment.
  3. A Schedule at midnight sets rings back to 0.
Reading a shared variableUse {{$shared.NAME}} in any text field, or pick it in a condition. Increment and Decrement are safe with many runs at once; Set is last write wins. You can also set one by hand in the console.

Problems you might see

CodeMeans
VARIABLE_NOT_A_COUNTERIncrement or Decrement on a variable that isn't a counter.
VARIABLE_NAME_RESERVEDThe name starts with __.
VARIABLE_EXPECTED_MISSINGCompare and set without a value to compare.

Problems found when you publish stop the publish and point at the node. Problems while a run is going fail the node, and its On failure setting decides what happens next. See the error codes for the API's own.