I urgently need help [Working With Array]

I have a workflow that receives data through WebHooks Node, use part of the data to do a lookup on Postgres DB, adds data from the first node to the results from the Postgres DB lookup by using SET node to format it, and then sends that data out with HTTP Node.

It works well but the problem is that, if the database lookup producers 2 or more results only the first results will have data from the First Node (WebHooks Node), other results will be sent out without data from the First Node (WebHooks Node).

Please I need you guys to help me out, How do I fix this?

Hey @David_OK!

Welcome to the community! :slightly_smiling_face:

Can you share your workflow with us? This will help me replicate your issue, and provide you a better solution.

If you’re not sure how to share your workflow, select all the nodes and copy them (use CMD+C or CTRL+C) and paste them here. Please omit any information that you don’t want to share with us.

Hope that helps

@jan Please help me out

Hey @David_OK,

Can you share the output for the Postgres node and the Set 1 node? I am not able to replicate the issue. I will need more time to set up Postgres, I think.

This is for the Set node after Postgres node*

[

{

“MobileNumber”
:
“8064371929”
,

“FullName”
:
“Brian Jones”
,

“SMS”
:
:wave: Thank you for signing up”
,

“Twilio_Number”
:
“+17044861421”

}
,

{

“MobileNumber”
:
“7092067872”
,

“FullName”
:
“Mr Jerry”

}
,

{

“MobileNumber”
:
“2135434477”
,

“FullName”
:
“Online Number”

}

]

[

{

“FIRST_NAME”
:
“Brian”
,

“LAST_NAME”
:
“Jones”
,

“MOBILE_NUMBER”
:
“8064371929”

}
,

{

“FIRST_NAME”
:
“Mr”
,

“LAST_NAME”
:
“Jerry”
,

“MOBILE_NUMBER”
:
“7092067872”

}
,

{

“FIRST_NAME”
:
“Online”
,

“LAST_NAME”
:
“Number”
,

“MOBILE_NUMBER”
:
“2135434477”

}

]

@harshil1712 are you there?

Hey, yes. I am taking a look at it right now.

@harshil1712 Thank you

Hey @David_OK,

You can use the Function node to add the data to each entry. The following code snippet might be helpful. Please note, you might have to make a few changes based on your workflow.

var arr = items[0].json;
var new_items=[]
var twilio_number = $node['Set for WebHook'].json["TWILIO_NUMBER"];
var sms = $node['Set for WebHook'].json["SMS"];
for (var i =0; i<arr.length;i++){
new_items.push({"Twilio_Number":twilio_number, "SMS":sms, ...arr[i]})
}
return [{json:new_items}];