Google sheet node executed only once

Hey! I’m experiencing an issue with Google Sheet node which is executed only once. I don’t know if this is a bug or a misunderstanding of how n8n works. I created a workflow to reproduce the issue:

A Functions node returns an array with several “spreadsheet-id”. The next node is a Google Sheet node which should read each spreadsheet based on all the “spreadsheet-id” returned by the previous nodes.

Finally, I just have a Slack node for debugging which get the data from the Gsheet node to send it in a channel. Only one message is sent to the channel while each spreadsheet should return a different message.

Is it a bug or am I missing an important concept of n8n? Thanks in advance!

Update: I get it worked with a custom loop but it seems a bit overcomplicated.

The Functions node named “Get single sheet” return a single item from the node “All sheets” at each iteration with runIndex, and the IF node returns false to stop the loop when runIndex < $items(“All sheets”).length.

Hi @fadrien, many thanks for sharing your solution!

You’re quite right, in many cases it shouldn’t be necessary to build a loop. Until your post I thought all exceptions are listed here, but that’s doesn’t seem to be the case here, so I’ll make sure to add the Google Sheet’s node read operation to the list.

If you can update your logic to use the lookup operation instead, you wouldn’t need the loop (but this would obviously depend on whether your sheets allow looking up data).

If you’d like to simplify your flow a bit, I think you could modify it like so (replace the NoOp node with your Slack node):

Example Workflow
1 Like

Thank you @MutedJam for the simplified flow. I tested it this morning and it works well but I encounter a really weird issue in some contexts. I don’t know if it’s related to Google Sheet node or Split in batches node.

As you can see, in the first screenshot, Google sheet node called “Get sheet data” is executed twice which is what I want.

When I change the execution order of all my nodes, the behavior is not the same: “Get sheet data” is executed only once (the error in the Functions node is caused by this issue). I didn’t change anything related to the loop.

So this is a special behavior in the Merge node described here:

When the “Wait all data” node from your screenshot is executed, it would try executing the Function node (which presumably fails because it doesn’t have the required data available yet). I am afraid that’s how it currently works, but you might want to vote on the feature request linked above to change this.

Thank you for the explanation. Is there any workaround to achieve what I’m trying to do?

Seeing the Merge node in your screenshot is running in Wait mode, I’d build a sequential flow here, e.g. something like this:

Example Workflow

Here, every node left of my “Process Data” Function node would run first, the Function node is then able to access all data.

Yes, this is what I did, but I wanted to know if there are any solutions to parallelize multiple actions. My sequential flow works fine but it’s quite slow.

Contacting multiple APIs at the same time and waiting for all the responses to do other actions would be great.