Function Node Only Processes 1 Item (Expected 5 Items from Loop)

Hello this is my configuration :

i m on premise :

  • n8n version: : 1.64.3
  • Database (default: SQLite): Postgress
  • n8n EXECUTIONS_PROCESS setting (default: own, main): : default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: : Debian 12

:memo: Problem Description:

I’m building a workflow that processes a list of CSV file records. I have a total of 5 items, one of which is a summary record (“fileName”: “Total”), which I later ignore.

The structure is as follows:

A Code node creates the 5 items

A Loop Over Items node processes them

A Replace Me node confirms that all 5 items go through

Then, in the Code1 Function node, I want to generate a new filename for each item

:exclamation:Issue:

Even though the Code1 node receives 5 items (I can confirm this in the input), it only outputs 1 item — it seems to process just the first one.
:camera: Workflow Screenshot:

Included in my post (see attached)
🔍 Debug & Observations:

Here’s what I currently have in Code1:

const data = $node["Code"];
const orga = data.json["Orga"];
const originalFilename = data.json["fileName"];
const newFilename = `_${orga}.csv`;

return {
  json: {
    originalFilename,
    newFilename
  }
};

:firecracker: Problem:

This accesses $node[“Code”].json, which only gives the first item — not all the items passed from the previous node.
:white_check_mark: What I Want:

I want the node to rename each file individually, and return 4 renamed files (excluding the “Total” item).


Use $json instead of $node[...] inside a Function node when you’re processing multiple items (especially after a Loop):

const dateExploitation = ""; // or use $node["foundDateExploitation"].json["dateOnly"];

const orga = $json["Orga"];
const originalFilename = $json["fileName"];
const newFilename = `${dateExploitation}_${orga}.csv`;

return {
  json: {
    originalFilename,
    newFilename
  }
};

:white_check_mark: Expected Output:

[
  { "originalFilename": "file-A.csv", "newFilename": "2025-05-16_1.csv" },
  { "originalFilename": "file-B.csv", "newFilename": "2025-05-16_2.csv" },
  ...
]

:paperclip: Attached:

Sample input data
1 Like

My problem is here :

Why got only one item out, but i have 5 item on input ?

why my output is only 1 ??

thanks

1 Like

Hi @Issa2024

image

You are setting the mode to Run Once for All Items…

Hello if i select Run Once for each ITEM i got this error :

n8n can’t see the var on the begin of the script

if someone can explain me please what is wrong ?

Hello @Issa2024

The code was using incorrect syntax and had some logic issues.
I’ve fixed it for you.


If anything is unclear, feel free to let me know, I’d be happy to explain it in more detail.