Passing Msg Object to SubFlow

Hi - first a warning, I am new to Node-Red :grinning:

What I am trying to do, is pass a Msg Object into a sub-flow. The contents of the object will change depending on its source, so I can't really map the data through the sub-flow input properties, unless I can map the object as a property.

All help greatly appreciated.

Welcome to the forums @Phil89a.

Not sure I understand the concern currently.
Can you explain in detail what it is your sub flow needs to do - maybe share a flow?

A sub flow is technically no different, to a standard flow - only it's contained in a single Node.

You can pass your msg object to the sub flow, and do what you want with that msg inside the sub flow, and spit out any changes to it.

If you mean, you need to change what you do in that sub flow based on the message - maybe use the msg.topic property to decide what happens inside that sub flow?

2 Likes

Passing an object to a subflow is no different to passing an object to any other node. Inside the subflow, just simply access the message properties you are interested in.

Don't be confused by the properties that you add to the editor for a subflow, these should be considered as environment variables. IE, set once at design time when you use an instance of the subflow. And you access them just like you would access any other environment variable inside of the subflow.

2 Likes

Ignore me - it was newbie error :face_with_open_eyes_and_hand_over_mouth:

For some reason my msg object was nil but it was an error in my flow. I literally just before reading your reply released my error and got everything working.

Yep, newbie error :face_with_open_eyes_and_hand_over_mouth:

I was misled by being able to define properties to pass to the sub flow, and my flow error, so thought it wasn't going to be possible. Now I know better :grinning:

1 Like

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