Context scope and complex variables possible?

Hello I want to store a javascript object in the flow context scope to keep a state over different runs of a flow
Example:

{ 
  "lastState": {
    "device1": timestamp,
    "device2": timestamp,
   }
}

Something like this does not work (non wokring code):

var lastReset = flow.get("lastReset")
var device = msg.device
lastReset[device] = Date.now()
flow.set(lastReset)
return msg

flow.set expects a string?

Is this possible with a function node?

flow.set expects two arguments
the name (string) of the context variable and the value (your object in this case )

try

var lastReset = flow.get("lastReset")
var device = msg.device
lastReset[device] = Date.now()
flow.set("lastReset", lastReset )
return msg

you can read more about using Context in Function nodes here

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.