Asked 1 month ago by VoidOrbiter118
Why does the n8n Google Sheets node repeat first sheet data when given multiple sheet names?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by VoidOrbiter118
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I'm working on an n8n workflow that uses a Google Sheets node to fetch rows from two sheets named "ONE" and "TWO". A previous code node provides an array with these sheet names as input.
What I expect: The node should run once per input, fetching data from each specified sheet and merging the results. For example, with the following data:
Sheet “ONE”:
ID |
---|
ONE A1 |
ONE A2 |
ONE A3 |
Sheet “TWO”:
ID |
---|
TWO A1 |
TWO A2 |
The expected output is:
JSON[ { "row_number": 2, "ID": "ONE A1" }, { "row_number": 3, "ID": "ONE A2" }, { "row_number": 4, "ID": "ONE A3" }, { "row_number": 2, "ID": "TWO A1" }, { "row_number": 3, "ID": "TWO A2" } ]
However, the actual output repeats the data from sheet "ONE":
JSON[ { "row_number": 2, "ID": "ONE A1" }, { "row_number": 3, "ID": "ONE A2" }, { "row_number": 4, "ID": "ONE A3" }, { "row_number": 2, "ID": "ONE A1" }, { "row_number": 3, "ID": "ONE A2" }, { "row_number": 4, "ID": "ONE A3" } ]
This leads me to ask:
Additional context:
Any insights on what I might be missing or how to resolve this would be greatly appreciated. Thanks!
Comments 0
•Answers 1
•Views 25
Answer by TychoAI Agent • 14 days ago
Below is some insight into what is happening and how to resolve the issue:
Yes – under normal conditions, when you pass multiple items into a node, n8n will execute the node once per input item. In your case, the expectation is that the Google Sheets node will run separately for the sheet named "ONE" and then for "TWO."
Even though multiple input items are received, what often happens is that the dynamic field (in your case, the sheet name) isn’t being re‐evaluated for each item. Instead, the parameter value is being set once (usually when you configure the node) and then reused for all input items. This means that if the first input item was “ONE” at the time you configured (or tested) the node, the node ends up fetching data only from that sheet each time.
Dynamic Expression:
Verify that the field where you specify the sheet name is set up using an expression (for example, using {{ $json.sheetName }}
or similar) so that it picks up the value from each input item. If the field is statically set, it will not update per item.
Node Execution Mode:
Confirm that the node is set to run per input item rather than “Run Once for All Items.” Sometimes, if you return an array and the node is configured with “Run Once for All Items” then the parameter is taken only from the first element of the incoming data.
Refresh Parameters if Needed:
In some cases further along in the setup (for example with mapping or cached column information), you might need to re-open the node settings so that the dynamic evaluation is reset.
If you are receiving your sheet names from the previous Code node, ensure that in your Google Sheets node the sheet name field is set up like this:
TEXT={{ $json.sheetName }}
Or if your output key is different, replace sheetName
with the proper key. This tells the node to use the current item’s value rather than a preset value.
Adjusting these settings should have the node pick up “ONE” and then “TWO” as separate dynamic inputs and merge their results as expected.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
No comments yet.