i tried creating a simpler flow. hope this is easier to understand.
where i run a SQL select staement against a datbase, using the "node-red-node-mysql" , depending on what node you are using for communicationg with database, this can varey.
in this case i set msg.topic as the sql statement like . msg.topic = "select * from table"
the result is an array of objects, where each object is a row from the table,
so in this case row one goes to mdbus 1 and row 2 to modbus 2.
so if i have a table that have a column named "IP" which has the ip adress.
then i would set modbus 1 'tcpHost' to msg.payload[0].IP
and modbus 2 'tcpHost' to msg.payload[1].IP
[0] is the first object in the array, [1] second etc.
Debug nodes, is realy great to see how the data is ouptut from nodes, ( just set it to "complete msg object, if you want ot se more than just payload)
[{"id":"95dd177d.0ec428","type":"function","z":"786aa205.67036c","name":"set ip MODSBUS 1 ","func":"\n//msg.payload is the output from the DB node, based on teh sql query. \n// in this case it was a select * from table.\n// this returns an array of objects where each object is a row from the table. \n // so msg.payload[0] would be row 1, msg.payload[1] is row 2 etc. \n \n // msg.payload[0].IP gets the value of the column IP\nlet IPfromDB = msg.payload[0].IP;\n\n// this is the payload and objects the modbus node require to be dynamically configured\n//, as seen in the help documentation in the sidebar for the nodemodbus-flex-connector.\n\nmsg.payload = { 'connectorType': 'TCP', 'tcpHost': IPfromDB, 'tcpPort': '502' ,'unitId': 1 };\n\n\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":1300,"wires":[["c04e4eef.d43cd"]]},{"id":"c65ab527.cd31d8","type":"function","z":"786aa205.67036c","name":"Set IP MODBUS 2","func":"\n//msg.payload is the output from the DB node, based on teh sql query. \n// in this case it was a select * from table.\n// this returns an array of objects where each object is a row from the table. \n // so msg.payload[0] would be row 1, msg.payload[1] is row 2 etc. \n \n // msg.payload[1].IP gets the value of the column IP\nlet IPfromDB = msg.payload[1].IP;\n\nmsg.payload = { 'connectorType': 'TCP', 'tcpHost': IPfromDB, 'tcpPort': '502' ,'unitId': 1 };\n\n\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":1360,"wires":[["bffc1174.11d6f"]]},{"id":"c2581f78.3ab79","type":"comment","z":"786aa205.67036c","name":"node-red-node-mysql","info":"This gets kicked off from another flow, the the localIpadress is set","x":440,"y":1260,"wires":[]},{"id":"c04e4eef.d43cd","type":"modbus-flex-connector","z":"786aa205.67036c","name":"RIO1","maxReconnectsPerMinute":4,"emptyQueue":false,"showStatusActivities":true,"showErrors":true,"server":"ab37667f.3b2f58","x":1010,"y":1300,"wires":[[]]},{"id":"bffc1174.11d6f","type":"modbus-flex-connector","z":"786aa205.67036c","name":"RIO2","maxReconnectsPerMinute":4,"emptyQueue":false,"showStatusActivities":true,"showErrors":true,"server":"fdab6cca.05a03","x":1010,"y":1360,"wires":[[]]},{"id":"cb8cb957.9889c8","type":"mysql","z":"786aa205.67036c","mydb":"66c70f7d.c4693","name":"","x":440,"y":1300,"wires":[["95dd177d.0ec428","c65ab527.cd31d8","e4e99373.7d716","dff4296d.e93f28"]]},{"id":"259a2600.834f3a","type":"inject","z":"786aa205.67036c","name":"set msg topic as SQL statement","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"select * from table","payload":"","payloadType":"date","x":210,"y":1300,"wires":[["cb8cb957.9889c8"]]},{"id":"e4e99373.7d716","type":"debug","z":"786aa205.67036c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":1240,"wires":[]},{"id":"dff4296d.e93f28","type":"debug","z":"786aa205.67036c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":1180,"wires":[]},{"id":"66c70f7d.c4693","type":"MySQLdatabase","z":"","name":"","host":"127.0.0.1","port":"3306","db":"databasename","tz":""}]