Set Context

The state manager. Explicitly creates, updates, or clears variables within the persistent WorkflowContext. Use this to normalize raw trigger data into clean, semantic variables for downstream logic.

Spec v1.1 State Assignment

Port Overview

Input ports
set
Set Context
Data
Output ports
onComplete
onError

Node Properties

Configuration for state assignment. The Set Context node can perform multiple operations in a single atomic pass, ensuring the WorkflowContext is updated before downstream nodes fire.

SetContextNode

Assignments

Property Type Default Description
assignments array[obj] required A list of operations to perform: { key, value, operation }.
Key: The destination path (e.g., $.status).
Value: Static data or expression (e.g., $.mqtt_1.payload.val * 1.1).
operation enum Set Set(Upsert) Creates a new key or overwrites an existing one.
Merge — Shallow-merges an object into an existing key.
Increment — Adds a value to a numeric variable.
Append — Adds an item to an array.
Clear — Removes the key from the context.

Operation Type Matrix

To ensure state integrity, operations expect specific data types. If an operation is performed on an incompatible type, the onError port is triggered.

Operation Expected Type Behavior & Example
Set Any Upsert: Creates or replaces.
Ex: $.priority = "High"
Merge Object Patch: Shallow-merges properties.
Ex: $.device + {"battery": 80}
Increment Number Math: Adds to existing value.
Ex: $.alarmCount + 1
Append Array Push: Adds to end of list.
Ex: $.history + "Alert Sent"
Clear Any Delete: Removes key from context.
Ex: $.tempToken
Implicit Initialization If an Increment or Append operation is performed on a key that does not exist, the engine initializes it as 0 or [] respectively before applying the change.
Semantic Normalization Raw payloads from triggers are often deeply nested (e.g., $.mqtt_1.body.sensors[0].val). Use a Set Context node at the start of your flow to map these to clean, reusable variables like $.currentTemperature. This makes your workflow modular and easier to maintain.

Port Detail

Handles the persistence of the new state before releasing control to the next node.

Input ports
set control
Triggers the assignment logic. All expressions are resolved against the current state before any writes occur.
Output ports
onComplete signal
Fires once the new state has been committed to the persistent WorkflowInstance store.
onError error
Fires if an expression fails (e.g., dividing by zero) or if an operation is invalid for the data type (e.g., incrementing a string).