I’m trying to build an n8n workflow with the following steps:
Read data from a Google Sheet using a GET operation.
Send each row into an AI Agent prompt to generate new content based on the row data.
Update the original Google Sheet using the UPDATE operation to insert the AI-generated result into the correct row.
The issue:
I can’t figure out how to match the AI response with the correct row in the Google Sheet. For example, I’d like to use a unique column like “Ticket Number” or “ID” to identify each row and make sure the correct row gets updated with the new data.
My question:
How can I reliably associate each AI result with its corresponding source row in the Google Sheet, based on a unique column value?
Are there any best practices to keep that link between the input data and the AI response throughout the flow?
The row_number is returned by the Google Sheets Node.
This row_number can be used to update the row of the sheet.
To avoid passing the row number trough the agent, it can be simply accessed with {{ $('get rows').item.json.row_number }}.
I used a Loop in the example, to see quick results, but it also works without the Loop.
A big thank you for your clear and effective solution regarding my issue on n8n.
Thanks to your explanation, I was able to use {{ $('get rows').item.json.row_number }} directly without having to pass it through the agent — it really simplifies the workflow.
Your example with the Loop was very helpful, and it’s great to know it also works without it!
Thanks again for your valuable help and quick response.