I’ve only been using n8n for a short time but have managed to figure a few things out. Now I am working on updating data in a Google Sheet. I get an email every day that gives me the total number of each item sold. I have a code node that extracts the date into Month, Day, Year and the quantity sold. Now where my issue is is that I cannot figure out how to put that number into a specific cell in my google sheet file.
My file is set up in the first row with A1 as Month and then the next column is 1, 2, 3, etc up to 31. In A2 - A13 are the month names. Since today is May 25, I would want to enter in the quantity into cell Z6 as that is where 25 and May line up. Please see picture.
You cannot just update a specific cell, it has to be the whole row. As you do not want to override the cells in the required row that were filled out in the previous days, you need to know the current values and reenter them together with the new value for the current date.
Thus, the steps are
Get the current rows
Pick the one corresponding to the current month (with the help of Merge node)
Populate the cell corresponding to the current date (with the help of Code node)
Update the row using “Month” column to match on
NOTE: “Date and Quantity” node formats the current date to extract the name of the month and the date as separate entities to be used later on in the flow for matching purposes.
@ihortom Thank you for showing me how to do this. This works great. I was curious if there was a way I could modify this to pull in old data. I tried adding a loop function, but I got an error on my code node. I changed it to “Run once for Each Item” and I get this error.
@jlhsolutions , I’ve made small changes to your workflow
NOTE:
There is no need to keep my original “Date and Quantity” node as you create the needed data in your own Code node “Code: Extract Date & Data Usage”. Therefore “Date and Quantity” node becomes redundant.
The Google spreadsheet to get the rows has Filter option added to pull only the row for the specific month (as opposed to all 12 rows). Just for optimization purposes.
“Code: Extract Date & Data Usage” is taken out of the Loop. I also have made some changes to the code, which you need to validate as it is not something I could test without the samples of the data. Basically, you want to make sure that the item has a proper value for the Month (and not ‘No match found’) to ensure that this Code node does not have the Loop breaking items in its output.