Pass different msg type to SQL node

Hello forum,

I have in a flow these data:

I want to send both to SQL node in order to make a query to insert both information into a table.
Could you suggest me the way to do this?
Should I convert the array to object and than use Join node?

Thanks a lot

You first need to get both messages into a single message so that all the values are available. See this article in the cookbook for an example of how to join messages into one object.

Thanks Colin.

I have already read the article suggested by you.

The point Is that I have one input as Array and another One as Object.
In the example seems that they are the same.
Can I use join also in this case or do I Need to convert all in Object? And eventually how can I do It?


You can join any payloads. Use the key/value pair mode as in the cookbook example and you will end up with the object in msg.payload.topic1 and the array in msg.payload.topic2. Then you can access both of those.


Do you mean this setting for the join node?

The point is that I need to assign topic to the first input of join.
How can assign the topic to the array (see debug of the node Out func 1 in first picture, coming from a query to a SQL database table)?

You can use a Change node to Set msg.topic to the string sql_data, or whatever name you want to give it. Set the Join node to Send After a number of message parts: 1, then you will get an output for every input message. If you only want to take action when you get an sql input then put a Switch node after the Join set to only pass a message if the topic is equal to sql_data.

Build the flow up one node at a time and use a debug node on the output of that node to check that it is doing what you expect, and that you understand the output. When that node is working then add the next one. Then you will not get to the stage of having several nodes with the wrong output and you won't have a clue as to why not.

A question, though. What are you going to do with the array? Will you be doing something with each row individually (or perhaps there is only ever 1) or will you be doing something with the whole array?

Thanks Colin.


Regarding your question: I expect only one value (primary key of first table) that I should pass to the second table together with other parameters that I insert by a form node.

OK. If you had multiple records in the array, to be handled individually, I was going to suggest splitting the array before the Join node so that there was one output from the Join for each record.

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