Hi I am still struggling a bit when it comes to repeating item
I have a json which has an array of data, I want to add this data one for each item in the array after the last function node to a Postgres database I do only manage to get to add the first one
jan
May 31, 2020, 9:56pm
2
There are multiple ways to write that. One in simple code would be this:
Thanks works great. Still learning;)
Stefan
June 19, 2020, 7:49pm
6
Hi,
how i can have the 3 entries as an output like in each row (table)
Array to …
Thanks,
Stefan
Stefan
June 19, 2020, 8:16pm
7
ForEach ? Would be the right function ?
Hey @Stefan , not sure if I understand well what you want to do. I’m guessing this is the response from an HTTP request and you want to get jus the patients. If so, check the example below.
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"url": "https://mockup-pj5l0yxsjrbr.runkit.sh/",
"options": {}
},
"name": "HTTP Request1",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
540,
300
]
},
{
"parameters": {
"functionCode": "const results = []\n\nfor (const item of items) {\n for (const patien of item.json.Response.patiens) {\n results.push({\n json: {\n patien, \n }\n })\n }\n}\n\nreturn results\n\n\n"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
750,
300
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "HTTP Request1",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request1": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
}
}
}
Stefan
June 20, 2020, 6:52am
9
RicardoE105:
{ “nodes”: [ { “parameters”: {}, “name”: “Start”, “type”: “n8n-nodes-base.start”, “typeVersion”: 1, “position”: [ 250, 300 ] }, { “parameters”: { “url”: “https://mockup-pj5l0yxsjrbr.runkit.sh/ ”, “options”: {} }, “name”: “HTTP Request1”, “type”: “n8n-nodes-base.httpRequest”, “typeVersion”: 1, “position”: [ 540, 300 ] }, { “parameters”: { “functionCode”: “const results = \n\nfor (const item of items) {\n for (const patien of item.json.Response.patiens) {\n results.push({\n json: {\n patien, \n }\n })\n }\n}\n\nreturn results\n\n\n” }, “name”: “Function”, “type”: “n8n-nodes-base.function”, “typeVersion”: 1, “position”: [ 750, 300 ] } ], “connections”: { “Start”: { “main”: [ [ { “node”: “HTTP Request1”, “type”: “main”, “index”: 0 } ] ] }, “HTTP Request1”: { “main”: [ [ { “node”: “Function”, “type”: “main”, “index”: 0 } ] ] } } }
you are great !! Thanks again