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.

{
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT \"FIRST_NAME\", \"LAST_NAME\", \"MOBILE_NUMBER\" FROM \"MY_MOBILE_CONTACT\" WHERE \"MOBILE_NUMBER_LIST_ID\" = '{{$node[\"Set for WebHook1\"].json[\"MOBILE_NUMBER_LIST_ID\"]}}'"
      },
      "name": "Postgres",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        845,
        279
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "8e958d43-d53c-4fa8-89f5-a98f677f22-4f",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        535,
        279
      ],
      "webhookId": "8e958d43-d53c-4fa8-89f5-a98f677f224f"
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "MobileNumber",
              "value": "={{$node[\"Postgres\"].json[\"MOBILE_NUMBER\"]}}"
            },
            {
              "name": "FullName",
              "value": "={{$node[\"Postgres\"].json[\"FIRST_NAME\"]}} {{$node[\"Postgres\"].json[\"LAST_NAME\"]}}"
            },
            {
              "name": "SMS",
              "value": "={{$node[\"Set for WebHook1\"].json[\"SMS\"]}}"
            },
            {
              "name": "Twilio_Number",
              "value": "={{$node[\"Set for WebHook1\"].json[\"TWILIO_NUMBER\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set for Postgress",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1005,
        279
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "TWILIO_NUMBER",
              "value": "=+{{$node[\"Webhook\"].json[\"query\"][\"TWILIO_NUMBER\"]}}"
            },
            {
              "name": "MOBILE_NUMBER_LIST_ID",
              "value": "={{$node[\"Webhook\"].json[\"query\"][\"MOBILE_NUMBER_LIST_ID\"]}}"
            },
            {
              "name": "SMS",
              "value": "={{$node[\"Webhook\"].json[\"body\"]}}"
            },
            {
              "name": "USER_ID",
              "value": "={{$node[\"Webhook\"].json[\"query\"][\"USER_ID\"]}}"
            },
            {
              "name": "FULL_NameVar",
              "value": "= {{$node[\"Webhook\"].json[\"query\"][\"FULL_NameVar\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set for WebHook1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        685,
        279
      ]
    }
  ],
  "connections": {
    "Postgres": {
      "main": [
        [
          {
            "node": "Set for Postgress",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Set for WebHook1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set for WebHook1": {
      "main": [
        [
          {
            "node": "Postgres",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

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}];