Function Node to search a content of a payload (Object Array)

Hello my dear supporter :slight_smile:

i am stucking at the following "problem":

I get two payloads:

{"ASYS":{"BOARD_REQUIREMENT":[{"$":{"l_MsgId":"359","s_Type":"AES03 Speed","s_SerNum":"077576","l_lane":"1","l_value":"0","l_pass":"0"}}]}}
{"ASYS":{"BOARD_DELIVERY":[{"$":{"l_MsgId":"369","s_Type":"AES03 Speed","s_SerNum":"077576","l_lane":"1","l_value":"1","l_pass":"0"}}]}}

Basically I dont wanna use the switch node, because, first I have to switch for Delivery and Requirement and after that to switch if value is 1 or 0.

I wanna have a function like:

If (("REQUIRMENT" == 1) && ("DELIVERY" == 0))
{ msg.payload = "MAGAZINunload_ready";
return [msg, null] // output 0

else if (("REQUIRMENT" == 0) && ("DELIVERY" == 1))
{ msg.payload = "MAGAZINunload_done";
return [null, msg] // output 0

But I have no Idea how to search the words nor how to combine the two payloads in one to search each cases for the word which are on the top level of the array object.
The word l_value I am setting to a variable and use it later in an if/else:

l_value = msg.payload.ASYS.BOARD_REQUIREMENT[0].$.l_value;

It is always a good idea to explore your development environment as there are often tools available to help you.



There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.


I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.