Repeat item from postgres query

Hi

We are again abit lost how to get the nodes to repeat per item

We have 2 postgres nodes one with 1 item and one with multiple item. We want it to repeat once per item from the last postgres node but also include one field from the postgres node with 1 item.

The node with a single item
inspectionodeData

The full workflow

The section with repeating items

we are trying to use this node to modify the input

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "//var inspectionidtemp=$item(0).$node[\"create inspection\"].json[\"id\"];\n\n\nconst returnItems = [];\n\n{\n\n    returnItems.push({json: {\n\"id\": $item(0).$node[\"get section templates\"].json[\"id\"].concat($item(0).$node[\"create inspection\"].json[\"id\"]),\n \"locationid\": $item(0).$node[\"get section templates\"].json[\"locationid\"],\n \"inspectionid\": $item(0).$node[\"create inspection\"].json[\"id\"],\n \"sectiontemplateid\": $item(0).$node[\"get section templates\"].json[\"id\"],\n \"department\": $item(0).$node[\"get section templates\"].json[\"department\"],\n \"title\": $item(0).$node[\"get section templates\"].json[\"title\"],\n \"description\": $item(0).$node[\"get section templates\"].json[\"description\"]\n    }});\n}\nreturn returnItems;\n"
      },
      "name": "value1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1400,
        190
      ]
    }
  ],
  "connections": {}
}

Not having tested it but something like that should be what you are looking for:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "const returnItems = [];\n\nfor (const item of items) {\n  returnItems.push({json: {\n    \"id\": item.json[\"id\"].concat($item(0).$node[\"create inspection\"].json[\"id\"]),\n    \"locationid\": item.json[\"locationid\"],\n    \"inspectionid\": $item(0).$node[\"create inspection\"].json[\"id\"],\n    \"sectiontemplateid\": $item(0).$node[\"get section templates\"].json[\"id\"],\n    \"department\": item.json[\"department\"],\n    \"title\": item.json[\"title\"],\n    \"description\": item.json[\"description\"]\n  }});\n}\n\nreturn returnItems;\n"
      },
      "name": "value1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        848,
        578
      ]
    }
  ],
  "connections": {}
}

Thanks! Works great, still trying to understand when to use what and how but it is coming, thanks for keeping up a great work.

1 Like

Great to hear that it works now. Have fun!