Updating multiple Google Sheets on Webhook Trigger

Greetings!

I am handling registrations for an inter school symposium and I would like to know the best approach to update multiple google sheets based on the data that I receive from the form handler webhook.

The symposium has multiple events. Each of these events has a corresponding google sheet in a drive folder. When a school submits the registration form, I receive data of the students that participate in various events. I want to check this data and then route specific chunks of info to separate google sheets, based on the event. Basically, what I am trying to achieve here is event-wise response sheets.

The webhook data that I receive is of the following schema:

{
  "body": {
    "fields": [
      {
        "key": "question_some_id",
        "type": "",
        "value": ""
      }
    ]
  }
}

At the start of the form, I have a checkbox asking for the events the school is participating in. This checkbox has a type of CHECKBOX (in the above structure) and value is a boolean depending on whether the user has selected the particular checkbox or not. There are 20 checkboxes for the 20 events that we have, each checkbox has its own key that identifies it in the above webhook response.

This is where I want to begin my filtering.

Each event name (or checkbox in the form) has also corresponding set of questions (like participant data) which is identified by their key. I have the set of key that correspond to each question (each event has 5-6 questions, each having their key). What I am aiming to achieve here is, to loop through the fields, check whatever checkbox the user has selected. Using the key of this checkbox, identify what event it is, what further questions correspond to this event (from the set of questions that I have corresponding to this event), and what google sheet the data (which is basically just a string put together from multiple questions in the set, like name and further participant data) must go into.

After this data has been extracted, I will perform further text sanitization and formatting and update a google sheet row with this data.

I have previously looked into the switch node, routing different values to different sheets, but I have been unsucessful in my tries. I wonder whether I should be using the Code node?

Please put me in the right direction.

Information on your n8n setup

  • n8n version: 1.100.1

This was a long read :slight_smile:

Ok, let’s see how close I got this:

The first page of the form requests the school information and the list of events they wish to participate in. Then for each event selected they get a next page, where they can write down participants. After completing the last one, the info is written to Google Sheets:

Appreciate the patience! Much thanks.

I have another question now, I have the following format in my google sheet:

How can I update values in the two sub-columns in Column C (Participants)?
My google sheet append row node is only showing the ‘Participants’ Column.
Is there a way to maybe specify what column specifically it should update for the data?
My data structure (after all transformation) is as follows (this participant data is specific to this event/google sheet only):


As you can see, only Column C is displayed.

Thanks.

hi,
is it possible to move create a row for name, class, and discord ?

Sorry, I don’t get what you mean.

Anyhow, I had to scrape that idea. I can achieve what I want now.

I have another question (sorry for the inconvenience :sweat_smile:),

I have an array of objects coming from a ‘Code’ node. I want the first object in the array to go to a google sheet node corresponding to a sheet. The second object then to another sheet and so on.

And I want that in the google sheet node, only the specific object of the current iteration is the input.

I currently have a split out node. I have added multiple google sheet nodes to it. The issue, the entire data coming from the previous code node is passed to this google sheet node. I only want a single object which corresponds to this iteration.

How can I achieve this?

this depends on how you process data in the code node - you can make it spit out answers one at a time (one for each input) or all together (one for all intputs). Alternatively you can split the answers out afterwards with the split out node.

If you need pieces to go to the different sheets you can be setting the sheet ids in the code (or later) and then hove only one sheet node, which takes the id and the values to set.

Which part?

Currently I have come up with solution of using a split out node and then a switch node which routes to different sheets based on the condition.

I have realized this will get very tedious, as I have 20 sheets to be filled, for each event.

About the input, it is all processed at once and is a single array of objects.
I split this array using the split out node and then use the switch for each item:

This sounds interesting. I would love to know how to update each sheet with only one google sheet node. I can inject the sheet id into the data object.
I’m assuming a loop node? I tried it and it only runs once:


What am I doing wrong here please?

I would need to look at the workflow you’ve created in more detail, could you embed it here?

Here it is:

I can see 19 items from the split out node going to the loop node but only one going to the google sheets node.

Not sure if the node provides you the exact data structure, so I’ll attach screenshots here:
split out node:

loop node:

and this is google sheet node:

as you can see, only 1 item is showing in the loop branch (output). not sure why

Ok, so from what I understand you Sheet in the Sheet document is named after the event, right? And the result of split out is each full form answer? Then you can feed split out directly into the google sheet node, and set the sheet ‘by name’ dynamically with {{ $json.eventName }}.

Yes. Sheets have same name as the event.

Actually, the entire response comes from one single form. The entire data is actually one single array. I split it and formatted it into the data that you can see from initial code nodes.

I can use {{ $json.eventName }} but, how do I determine what values to send? In the participants field as you can see here:

I can only select a fixed index to send as you can see.
If it possible to pass each object in the array as a separate output, then I can always use the zeroth index and a single google sheet.

What I mean exactly is. If a user selects lets say AestheticX and click noice events (these are names of some of the events that I have) in the google form, then the data after transformation will be an array containing two objects. In this case then the aestheticx participant data is at the zero’th index, click noice at one. However if a user skips through click noice and chooses some other data, then that event’s participant data will be at the 1st index (assuming they still fill the aestheticx event ofc).

Currently what I need to figure is how to pass each item/object in the array as a separate item so that its always at the zeroth index and I have no issues with determining what index to use. Then I can use directly the google sheet node. Loop node currently outputs one item only from the array that split node sends it, exactly as I want:

However this loop node is terminating at the first step only. I would like it to continue to loop through all the 19 items. I can just change the google sheet id to a expression which is the name of the event then to update the corresponding sheets.

I’m however not sure how to do that.

You can join values of the array the participants to be a single string if this solves your problem (of having to choose a single index).

Alternatively you can re-structure the output of the code node in a way that makes it easier to paste the values into the google sheets node

I mean, I already have the single output coming out of the loop node. If I always have only one single item, I can always use the zeroth index.
What I don’t understand is why the loop terminates and doesn’t go onto the next item in the array.

Difficult to say without being able to look through the whole flow.
If you can embed your full workflow, I will change the sheet name to mine and try to repro to see why your loop isn’t looping.

I can’t seem to paste the entire workflow here due to character limit. Please find it here: { "nodes": [ { "parameters": { "httpMethod": "POST", - Pastebin.com

Hi. Have you had any luck with this? Sorry for disturbing you

Ok, created the sheets and ran your workflow, right now we have 19 items coming out of the code node and I see that the loop is ran 20 times (19 for each item and 1 to go the the done branch after the last item)

The sheet is populated rather oddly, because the participants are a single array of items. How would you like it to be populated on the sheet instead of

S.No School Participants
school_name [{name:ax_1_name,class:ax_1_class},{name:ax_2_name,class:ax_2_class}]

I would assume something like

S.No School Participants Class
school_name ax_1_name ax_1_class
school_name ax_2_name ax_2_class

?

Yep the latter case.

Its a single array because each sheet has different values, this is participant data corresponding to each event.

How were you able to trigger the loop?