Using boolean status from context

Evening all,

I'm tring to find a way to use true/false status of an object stored in context to drive some later code. I'm hoping to read multiple values (and booleans) from context into multiple payloads, and have multiple outputs from a single function. The Int values I read from Context are coming out as expected, but booleans are undefined :frowning:

Is there a simple way of getting a true/false output from a function node?
My flow is large, so here's just the principle I'm using to no avail:

return [

    { payload: flow.get('mbValues.Alarm_b8.value') }

    ]
    
;

That should work.
Check in the Context pane in the editor what is actually in that field.
Post a screenshot showing it if you think it is correct.

As context stores are often file or database based, I'm not sure if booleans get returned as booleans - they may come back as strings.

How strange... payload: flow.get('mbValues.Alarm_b8.value') did not work, but I tried copying the path directly from the Context pane and payload: flow.get('mbValues["Alarm_b8"].value') does...

The Ints appear to work whichever way I call up the object values... so should I be referencing all values from context in this latter way, or just boolean values?

Could you copy/paste the code that works and the code that doesn't please?
Check it still doesn't work before posting. Maybe put both lines of code in, with one commented out for each test.

Hi Colin, sure...

This works:

return [


    { payload: flow.get('mbValues["StateMachine_u16"].value') },

    ]
    
;

This still doesn't work:

return [


    { payload: flow.get('mbValues.StateMachine_u16.value') },

    ]
    
;

How are you writing the data to context?

I'm capturing modbus data after a buffer parse, like so

// update mbValues
flow.set(`mbValues.${msg.topic}`, { ...flow.get(`mbValues.${msg.topic}`), ...msg.payload })

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