Hi n8n community! i have a probably very simple problem with the item lists node. i studied the documentation and the forum, but im not quite sure if i understood the functionality correct.
Describe the issue/error/question
i cant seem to get the node to work in aggregate mode. Basically what i want to do is to merge the outputs of different paths of my workflow in order to be able to reference all the data and use the data returned by my if-structure. i tried to do this with a merge node that connects the true and false branch of my if-structure, but when i did that it would always run both branches. is the item lists node what i should use? any help is appreciated, also please dont judge too harsh on my workflow snippet, i am aware its far from ideal and i have a lot to learn
What is the error message (if any)?
ERROR: Couldn’t find the field ‘address’ in the input data
Please share the workflow
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
-920,
1100
]
},
{
"parameters": {
"mailbox": "Inbox",
"postProcessAction": "nothing",
"format": "resolved",
"options": {}
},
"name": "IMAP Email",
"type": "n8n-nodes-base.emailReadImap",
"typeVersion": 1,
"position": [
-920,
1260
],
"credentials": {
"imap": {
"id": "1",
"name": "IMAP account"
}
}
},
{
"parameters": {
"functionCode": "//const itemsMail = $items(\"SplitInBatches\");\n//const htmlExtract = $items(\"HTML Extract\");\n//console.log(htmlExtract);\n//const plainTextReturn = $items(\"plainTextReturn\");\n//console.log(plainTextReturn);\n\nconst response = [];\n\n\n\n//var textReplaced = itemsMail[0].json.textPlain.replace(/(\\r\\n|\\n|\\r)/gm,\".\");\n//if (textReplaced == []){\n const html = $items(\"HTML Extract\");\n var textReplaced = html[0].json.desc.replace(/(\\r\\n|\\n|\\r)/gm,\"<br>\");\n textReplaced = JSON.stringify(textReplaced);\n//}\n\nresponse.push({json:{\"body\":textReplaced.toString()}});\nreturn response;"
},
"name": "formatDescription",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
60,
840
]
},
{
"parameters": {
"conditions": {
"boolean": [],
"string": [
{
"value1": "={{$node[\"SplitInBatches\"].json[\"text\"]}}",
"operation": "isEmpty"
}
]
}
},
"name": "IF4",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-340,
1060
]
},
{
"parameters": {
"functionCode": "const allItems = $items(\"SplitInBatches\");\n\nconst responseNew = [];\nfor (const item of allItems) {\n var subject = item.json.subject;\n subject = subject.replace(\"#\",\"\");\n var aSplit =[];\n aSplit = subject.split(\"Request Nr. \");\n //console.log(aSplit);\n //console.log(item.json.subject);\n if (aSplit.length>1){\n responseNew.push({json:{\"smaxid\":aSplit[1].substring(0,5)}});\n }\n else {\n aSplit = subject.split(\"Request \");\n if (aSplit.length>1){\n responseNew.push({json:{\"smaxid\":aSplit[1].substring(0,5)}});\n }\n }\n}\nreturn responseNew;\n\n\n\n\n// funktionierender return: responseNew.push({\"json\":[aSplit[1].substring(0,5)]});"
},
"name": "cut id",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
-160,
1260
],
"alwaysOutputData": true
},
{
"parameters": {
"batchSize": 1,
"options": {}
},
"name": "SplitInBatches",
"type": "n8n-nodes-base.splitInBatches",
"typeVersion": 1,
"position": [
-520,
1260
]
},
{
"parameters": {
"values": {
"number": [
{
"name": "counter"
}
]
},
"options": {}
},
"name": "Init Counter",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
-720,
1260
]
},
{
"parameters": {
"dataPropertyName": "html",
"extractionValues": {
"values": [
{
"key": "desc",
"cssSelector": "p"
}
]
},
"options": {}
},
"name": "HTML Extract",
"type": "n8n-nodes-base.htmlExtract",
"typeVersion": 1,
"position": [
-100,
840
],
"alwaysOutputData": true
},
{
"parameters": {
"functionCode": "const result = [];\nconst from = $item(0).$node[\"SplitInBatches\"].json[\"from\"];\nconst address = from[\"text\"];\nconsole.log(\"address: \"+ address);\n\nvar aSplit = address.split(\"<\");\nresult.push({json:{\"address\":aSplit[1].replace(\">\",'')}});\n//result.push({json:{\"from\":from[\"text\"]}});\nreturn result;\n\n\n//result.push($item(0).$node[\"IMAP Email\"].json[\"from\"]);\n\n\n//var aSplit = from.split(\"<\");\n// responseNew.push({\"json\":[aSplit[1].replace(\">\",'')]});\n\n\n\n\n\n// working push: result.push({\"json\":[aSplit[1].replace(\">\",'')]});"
},
"name": "cut mailaddress",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
20,
1260
]
},
{
"parameters": {
"functionCode": "//const itemsMail = $items(\"SplitInBatches\");\n//const htmlExtract = $items(\"HTML Extract\");\n//console.log(htmlExtract);\n//const plainTextReturn = $items(\"plainTextReturn\");\n//console.log(plainTextReturn);\n\nconst response = [];\n\nconst text = items[0].json.text;\nconsole.log(\"textt: \"+text);\n\n//var textReplaced = itemsMail[0].json.textPlain.replace(/(\\r\\n|\\n|\\r)/gm,\".\");\n//if (textReplaced == []){\n //const mail = items.json;\n //console.log(items.json);\n var textReplaced = text.replace(/(\\r\\n|\\n|\\r)/gm,\"<br>\");\n textReplaced = JSON.stringify(textReplaced);\n//}\n\nresponse.push({json:{\"body\":textReplaced.toString()}});\nreturn response;"
},
"name": "formatDescription1",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
-40,
1060
]
},
{
"parameters": {
"operation": "aggregateItems",
"fieldsToAggregate": {
"fieldToAggregate": [
{
"fieldToAggregate": "address"
}
]
},
"options": {}
},
"name": "Item Lists",
"type": "n8n-nodes-base.itemLists",
"typeVersion": 1,
"position": [
280,
1180
]
}
],
"connections": {
"IMAP Email": {
"main": [
[
{
"node": "Init Counter",
"type": "main",
"index": 0
}
]
]
},
"formatDescription": {
"main": [
[
{
"node": "Item Lists",
"type": "main",
"index": 0
}
]
]
},
"IF4": {
"main": [
[
{
"node": "HTML Extract",
"type": "main",
"index": 0
}
],
[
{
"node": "formatDescription1",
"type": "main",
"index": 0
}
]
]
},
"cut id": {
"main": [
[
{
"node": "cut mailaddress",
"type": "main",
"index": 0
}
]
]
},
"SplitInBatches": {
"main": [
[
{
"node": "IF4",
"type": "main",
"index": 0
},
{
"node": "cut id",
"type": "main",
"index": 0
}
]
]
},
"Init Counter": {
"main": [
[
{
"node": "SplitInBatches",
"type": "main",
"index": 0
}
]
]
},
"HTML Extract": {
"main": [
[
{
"node": "formatDescription",
"type": "main",
"index": 0
}
]
]
},
"cut mailaddress": {
"main": [
[
{
"node": "Item Lists",
"type": "main",
"index": 0
}
]
]
},
"formatDescription1": {
"main": [
[
{
"node": "Item Lists",
"type": "main",
"index": 0
}
]
]
}
}
} "type": "main",
"index": 0
}
]
]
},
"formatDescription1": {
"main": [
[
{
"node": "Item Lists",
"type": "main",
"index": 0
}
]
]
}
}
}
Share the output returned by the last node
Information on your n8n setup
- n8n version: 0.181.1
- Database you’re using (default: SQLite): –
- Running n8n with the execution process [own(default), main]: –
- Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker
edit: screenshot of my workflow while i try to fix the code snippet:
basically what i am trying to achieve is to consolidate all the information from the functions on the left side, so i can use them in the http-requests on the right side.