I have node that produces a msg.payload object with two contents:
activity
status
I need to continue the flow only when 'activity' = 48481328 and 'status' = 2.
I'm new to node red and struggling to find an example of how to achieve this. I assume the Function node will do it, I just need some help to write it.
You can do it with a function node, 2 switch nodes in series and probably with a change node using JSONata. I may have missed some options too.
Easiest with a function node though probably.
const activity = msg.payload.activity
const status = msg.payload.status
if ( activity === '48481328' && status === 2 ) return msg
// You must make sure you remove the default `return msg`
//return msg
Note two things:
I've assumed that the status is numeric, but activity is a numeric string. Make sure you get this right.
I've used a positive test. This is the recommended best practice because positive tests are generally easier to comprehend. However, they can sometimes result in more long-winded code. In this case, the impact is that you MUST remove the default return msg at the end of the function code.
With a negative test, the code would look like:
const activity = msg.payload.activity
const status = msg.payload.status
// use an OR and return nothing
if ( activity !== '48481328' || status !== 2 ) return
return msg