Flow.set changes flow name from 01 to 1

Morning Team.

I have a function node that sets some context values.

For some odd reason if I look at my context flow data the name gets changed from "config_alarm.alarm.zones.01.state" to "config_alarm.alarm.zones.1.state"

Example Message

{"_msgid":"ab716e5b1004ff95",
"payload":"arm",
"topic":"/alarm/zone/arm/normal/01,02,03",
"_event":"node:3e0554c5207a26f4"}
var var_str_zone_reference = msg.topic.substring(msg.topic.lastIndexOf("/") + 1);
node.warn(var_str_zone_reference)

var var_array_zone_reference = var_str_zone_reference.split(",");
node.warn(var_array_zone_reference)

for (var var_str_zone_reference of var_array_zone_reference) {
    node.warn(var_str_zone_reference)

    msg.topic = "config_alarm.alarm.zones." + var_str_zone_reference + ".state";
    node.warn(msg.topic);

    if (msg.payload == "arm" || msg.payload == "disarm"){
        flow.set(msg.topic, msg.payload + "ed");
        flow.set
    }
}
   

The flow.set() function that writes to context is taking 01 and parsing it as a number 1 and is creating an array in context.
If you want a object with key 01 then use square bracket notation.
e.g.

    msg.topic = "config_alarm.alarm.zones['" + var_str_zone_reference + "'].state";

or better still use the best practice form of property names , which should start with a letter or underscore.
e.g.

    msg.topic = "config_alarm.alarm.zones._" + var_str_zone_reference + ".state";

p.s. Hi and welcome to the forum.

1 Like

@E1cid, that works thanks so much for the help!!!

So if flow.set sees an object key which can be converted to a number it does so and you end up with an array?

Is that a feature of the flow.set code, or of Javascript in general?

1 Like

Without looking at the underlying flowset code, i can not say. Seems a bit of a strange behaviour, possible bug? But it is not good practice to use numbers as object keys.

1 Like

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