How should I use Loop Over Items node?

I can not get Loop Over Items working. My JS code returns 10 items, but Loop Over Items processes only 2 of them. Looks like my flow overrides input for Loop Over Items, but I don’t understand how to fix it.

(I tried to connect If image already generated equal to true with Loop Over Items, but it doesn’t help)

hello @and7ey can you share workflow with sample data?

I’ve made a sample, I expect to receive 2 messages in reply, but respond to chat is executed only for the first item

{
“name”: “Test”,
“nodes”: [
{
“parameters”: {
“jsCode”: “return [\n { json: {\n\t\t\t\t"text": \n\t\t\t\t"Hello, this is my first phrase!",\n\t\t\t\t"voice_id": \n\t\t\t\t"rHWSYoq8UlV0YIBKMryp"\n\t\t\t}\n }, \n { json: \t\t\t{\n\t\t\t\t"text": \n\t\t\t\t"And this is what another character replies",\n\t\t\t\t"voice_id": \n\t\t\t\t"rHWSYoq8UlV0YIBKMryp"\n\t\t\t}\n }\n];”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
208,
0
],
“id”: “05e76a5b-50b0-4a4b-b2fa-1b808dc777d8”,
“name”: “Code in JavaScript”
},
{
“parameters”: {
“options”: {}
},
“type”: “n8n-nodes-base.splitInBatches”,
“typeVersion”: 3,
“position”: [
416,
0
],
“id”: “4a80600a-686a-470e-b6c0-92043da35493”,
“name”: “Loop Over Items”
},
{
“parameters”: {
“message”: “={{ $(‘Code in JavaScript’).item.json.text }}”,
“options”: {}
},
“type”: “ @n8n/n8n-nodes-langchain.chat”,
“typeVersion”: 1,
“position”: [
672,
16
],
“id”: “c6a004c4-5aa4-47ea-9a91-4c9d483f7301”,
“name”: “Respond to Chat”
},
{
“parameters”: {
“options”: {
“responseMode”: “responseNodes”
}
},
“type”: “ @n8n/n8n-nodes-langchain.chatTrigger”,
“typeVersion”: 1.4,
“position”: [
0,
0
],
“id”: “5d493ff7-2b2d-4a6d-81df-ac715eebb17f”,
“name”: “When chat message received”,
“webhookId”: “5f694c2b-4d63-4b76-a080-286a5ff05240”
}
],
“pinData”: {},
“connections”: {
“Code in JavaScript”: {
“main”: [
[
{
“node”: “Loop Over Items”,
“type”: “main”,
“index”: 0
}
]
]
},
“Loop Over Items”: {
“main”: [
,
[
{
“node”: “Respond to Chat”,
“type”: “main”,
“index”: 0
}
]
]
},
“When chat message received”: {
“main”: [
[
{
“node”: “Code in JavaScript”,
“type”: “main”,
“index”: 0
}
]
]
},
“Respond to Chat”: {
“main”: [
[
{
“node”: “Loop Over Items”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“active”: false,
“settings”: {
“executionOrder”: “v1”
},
“versionId”: “85825166-13fe-4c8c-a274-95f3040dc961”,
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “c172a29399dc1695c4e4ebd55e1ca8793799145ee04c4672fbea0a3bdc4ee854”
},
“id”: “H7l9BTWgyu36oEZm”,
“tags”:
}

Here is another sample. Again I expect HTTP Request to be executed 2 times, but it executes again and again

{
“name”: “Test”,
“nodes”: [
{
“parameters”: {
“jsCode”: “return [\n { json: {\n\t\t\t\t"text": \n\t\t\t\t"Hello, this is my first phrase!",\n\t\t\t\t"voice_id": \n\t\t\t\t"rHWSYoq8UlV0YIBKMryp"\n\t\t\t}\n }, \n { json: \t\t\t{\n\t\t\t\t"text": \n\t\t\t\t"And this is what another character replies",\n\t\t\t\t"voice_id": \n\t\t\t\t"rHWSYoq8UlV0YIBKMryp"\n\t\t\t}\n }\n];”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
208,
0
],
“id”: “05e76a5b-50b0-4a4b-b2fa-1b808dc777d8”,
“name”: “Code in JavaScript”
},
{
“parameters”: {
“options”: {
“reset”: true
}
},
“type”: “n8n-nodes-base.splitInBatches”,
“typeVersion”: 3,
“position”: [
416,
0
],
“id”: “4a80600a-686a-470e-b6c0-92043da35493”,
“name”: “Loop Over Items”
},
{
“parameters”: {},
“type”: “n8n-nodes-base.manualTrigger”,
“typeVersion”: 1,
“position”: [
0,
0
],
“id”: “665f2ca8-4d96-4cfa-a65e-2e53f97799e0”,
“name”: “When clicking ‘Execute workflow’”
},
{
“parameters”: {
“method”: “POST”,
“url”: “``https://api.restful-api.dev/objects”``,
“sendBody”: true,
“specifyBody”: “json”,
“jsonBody”: “{\n "name": "Apple MacBook Pro 16",\n "data": {\n "year": 2019,\n "price": 1849.99,\n "CPU model": "Intel Core i9",\n "Hard disk size": "1 TB"\n }\n}”,
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.3,
“position”: [
624,
96
],
“id”: “1a20de70-2237-4fd5-ab36-bdc5d1ef4cec”,
“name”: “HTTP Request”
},
{
“parameters”: {
“jsCode”: “console.log($input.first().json.id)\n\nreturn {json: {}};”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
832,
96
],
“id”: “5fd47859-7359-4bf2-9169-cc6369ddd4d1”,
“name”: “Code in JavaScript1”
},
{
“parameters”: {
“amount”: 1
},
“type”: “n8n-nodes-base.wait”,
“typeVersion”: 1.1,
“position”: [
1040,
96
],
“id”: “c682217b-3602-456b-80db-4bd5f94c5e0e”,
“name”: “Wait”,
“webhookId”: “d3151442-4846-42ce-be62-f3156733f372”
}
],
“pinData”: {},
“connections”: {
“Code in JavaScript”: {
“main”: [
[
{
“node”: “Loop Over Items”,
“type”: “main”,
“index”: 0
}
]
]
},
“Loop Over Items”: {
“main”: [
,
[
{
“node”: “HTTP Request”,
“type”: “main”,
“index”: 0
}
]
]
},
“When clicking ‘Execute workflow’”: {
“main”: [
[
{
“node”: “Code in JavaScript”,
“type”: “main”,
“index”: 0
}
]
]
},
“HTTP Request”: {
“main”: [
[
{
“node”: “Code in JavaScript1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code in JavaScript1”: {
“main”: [
[
{
“node”: “Wait”,
“type”: “main”,
“index”: 0
}
]
]
},
“Wait”: {
“main”: [
[
{
“node”: “Loop Over Items”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“active”: false,
“settings”: {
“executionOrder”: “v1”
},
“versionId”: “36ecdff6-3419-43b6-bc3b-e9aaa20a53d5”,
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “c172a29399dc1695c4e4ebd55e1ca8793799145ee04c4672fbea0a3bdc4ee854”
},
“id”: “H7l9BTWgyu36oEZm”,
“tags”:
}

I believe I have a similar issue. I have been trying to create a workflow that reads a directory via FTP, extracts the files of the directory (filtering them by certain criteria) and feedsback the inner directories to the start of the loop, keeping the filtered files.

The problem is that the first loop works great, and returns a bach of 4 directories that are feeded into the head of the loop, but when they reach the FTP node, it fetches all the incoming directories and spits all items as one bach, independently of the directory they belong, to the next node, loosing valuable information. I thought that I could use a loop node that spits each directory independently, but that didn’t solve the problem.

As far as I have understood, it is because the loop node can’t be feeded with more input as it just assumes that the incoming items are the result of the loop thus spitting them through the ‘done’ output branch.

I whish there was a node that spits items in baches of one and also accepts more input, creating a kind of queue or something similar.

This is a small example of what I mean, if anyone could help: I want to feed directories inside the loop again, but keeping the one batch per item. I also tried using reset in Loo Over Items node, but It just makes it ignore any item that is not the first directory of the batch.

In this one you have set reset to true
make it false

for this one:

wait for user reply to false made it response twice for 1 message:

you are doing loop but have not connected if node false output to loop.

You have connected it to filter node.

1 Like

I tested the direct loop option but gives a similar result.

can you share workflow?

also do create another topic in question it would be better.