Toggle boolean state of context value

Is there a way of toggling a context value
i.e. if it's false - set it true and vice versa

(apart from a function node method)
while typing I came up with this

but is there a nicer way?

Perhaps JSONata...

Set msg.payload.state
To the value msg.payload.state != true

When the value is false, the equation will return true. When the value is true, the equation will return false.


1 Like

Sorry that's for a msg - you can get flow context but to be honest a function would be easier

Alternatively, you can have a multi-step change node. First would copy the flow value into a temporary msg property, then do the equation I said, then copy the result back in the flow property.

1 Like

I actually can't get my method to work either - I think I may be being hit by JS what it true (or false) issues!

Function node it'll have to be :frowning:

You would not need a multi step change node.

@cymplecy Using the change option would never work as the order of the search would need to be reversed for true and false. Would be possible if you added a switch node so the replace for true/false could be separated.



But I was on mobile and not able to remember the exact jsonata fn call for getting context.

1 Like

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