Hi,
I’m trying to understand why this latching workflow is taking the path it is (see attached image).
The Latch expression is false.
The Reset expression is true.
The Latch was already ‘latched’ (wasLatched = true) so should not have latched again.
And even though the Reset is true, it left the node latched.
Maybe the flags I’m setting need to be ‘treat as JSON’ so the true and false are not ‘true’ and ‘false’? But that still doesn’t answer why it went through the true side even though it was already latched.
Any insight would be helpful.
Thanks, Stephen
Maybe the flags I’m setting need to be ‘treat as JSON’ so the true and false are not ‘true’ and ‘false’?
You are correct that the underlying issue is that the flags are strings instead of booleans. When Losant evaluates expressions, it follows the rules of JavaScript:
> if("false") { console.log('this is true'); }
this is true
Like you said, you can fix this by using the ‘treat as JSON’ option, which will cause the values to be parsed as booleans. Alternatively, you can change the conditions to check for strings:
{{working.setLatch}} === 'true'
But that still doesn’t answer why it went through the true side even though it was already latched.
The reason it took the true path is because the reset expression also evaluated to true. Whenever the reset expression evaluations to true, the latch resets and that invocation of the node will take the true path. Based on how the latch expression evaluations, it may or may not then re-latch.
Thank you - that helps.
Much appreciated,
Stephen