Update multiple rows in Google Sheets based on parent-child relationship

Hi everyone,

I’m still learning n8n, so it’s very possible that the solution is right in front of me and I just don’t see it yet :slightly_smiling_face:

I’m trying to update multiple rows in Google Sheets, but I couldn’t make it work, even after trying several approaches.

My Google Sheets structure

I have a table with the following columns:

  • name – category name

  • parent_name – parent category name (the parent exists in the name column, but not every category has a parent)

  • name_id – ID of the category

  • parent_id – ID of the parent category (this is what I want to fill automatically)

Example logic:

  • If parent_name is empty → this is a root category

  • If parent_name is not empty → this category has a parent

What I’m trying to achieve

I have a list of many categories with parent-child relationships.

My goal is to build an automation in n8n that:

  1. Reads all rows from Google Sheets

  2. Finds all rows where parent_name is NOT empty

  3. For each of those rows:

    • Finds the row where name == parent_name

    • Takes its name_id

    • Writes this value into parent_id of the child category

In short:

Match parent_namename, and copy name_idparent_id

What I tried

  • Google Sheets → Get Rows + Update Row

  • Using AI Agent (probably not needed)

  • Different ways to loop through rows

But I always end up:

  • Updating only one row

  • Or not updating anything at all

I feel like I’m missing something basic about looping / batch processing or how to correctly update multiple rows.

Question

What is the correct n8n pattern for this use case?

  • Should I use Split In Batches?

  • Should I build a lookup object first?

  • Is there a recommended approach for updating multiple rows based on relationships inside the same sheet?

Any guidance or examples would be greatly appreciated :folded_hands:
Thanks in advance!

Hey @Pavel_Shein !

Did a quick follow on requiremnts… and draft something quick before dinner is ready…

Letme know.
Cheers!

Hi! I tried your example workflow, but unfortunately it didn’t work for me as-is. However, I modified it a bit based on your idea, and now I have a working version. At the moment, I’m able to find the parent category name_id and correctly write it into parent_wp_id.

There is still an issue though. The same parent_wp_id needs to be written to multiple rows (when a parent category has several subcategories). During the update, all similar rows are being skipped — meaning if there are multiple subcategories with the same parent, only the first one gets the parent_wp_id, and the rest are not updated.

It seems that somewhere in the update or matching logic a non-unique key is being used, so the update only affects one row. Could you please advise how to correctly configure the workflow so that all child rows (all subcategories) get updated, not just the first one?

Hey @Pavel_Shein

I am not at PC right now, so can t edit thr workflow… but I gave you a good example(“sorry” for not making exactly what you “demanded”)…

To solve this “issue” further:

SplitInBatches with batchSize: 1 before Updating… and

Replace $(‘Get row(s) in sheet6’).item.json… with $json… in the Update node(that was with a purpose, since you need fresh data not referenced from back)…then the workflow will update each matching row in turn, not just the first one.

Have fun n8n-ing!

1 Like

Thanks a lot for your help!

I took your suggestion as a base and built a slightly different workflow on top of it, and now it’s working as expected.

I’m not 100% sure yet if this is the “best” or most optimal solution, but it works for my case so far. I’ll test it more to make sure there are no edge cases or hidden issues.

Thanks again for pointing me in the right direction — it really helped :+1:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.