Best answer

Test to see if Google Sheet exists


Userlevel 1

Hi,

We have an existing Zap that is triggered when a Gravity Form submission is sent. We also generate a PDF with each GF submission.

We then test to see if a folder exists in Google Drive, and if not we create a folder and the upload the PDFs to that. In this case a course ID and name.

So far so good.

We’re now trying to take data from the same GF form submissions to populate a Google Sheet in the same folder created in the previous steps. 

So we need to test to see if the Sheet already exists, if not, create it in the new folder. We will use data from the GF forms to check the sheet exists or to create the sheet if it doesn’t.

We would then add rows to that Sheet in subsequent steps.

Is it possible to do this i.e. test to see the sheet exists in the folder and if not create it there?

Thanks

Phil

 

icon

Best answer by MohSwellam 21 October 2022, 16:29

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

14 replies

Userlevel 7
Badge +8

Hi @philthebass 

 

You will need to have a specific name (probably something that relates to the data coming from the GF OR maybe a static name for all the Google Sheets since they are in different folders on Drive) and then use the Action Find a File in Google Drive, you can also specify the File Type as Google Sheets (but you need the Name of the sheet as it is a required field)

 

The folder where the search happens can be dynamic. 

Userlevel 1

Hi @MohSwellam 

Thanks for your help.

Yes, we’re creating the Sheet using data from the form submission- in this case Course ID + Course Name.

Based on your suggestions, I have set up a step to Find A File and set up the options to create the file if it doesn’t exist and place it in the folder from the previous step.

 

However, I can’t seem to be able to add rows in the next step.

 

Am I doing something wrong here.

Thanks again.

 

Phil

Userlevel 7
Badge +8

Hi @philthebass 

 

That is correct actually, except in the Worksheet part you need to map the sheet you found in the previous step. So click in Custom, then check the data from the previous step, it should include the Google Sheets ID , this is the data you need to map here. 

 

Let me know how it goes. IF this doesn't work, please screenshot the data from the test of the Find A File step 

Userlevel 1

Hi @MohSwellam 

 

I’ve tried getting the dynamic ID for the Find A File Step like this

 

 

But I still get errors

 

Not sure what to try next.

Thanks

Phil

Userlevel 7
Badge +8

Hi @philthebass 

 

We are almost there ;) The Worksheet is the table, so you need to input the table Id here (not the file ID)

Userlevel 1

Hi @MohSwellam ,

 

Where do I find the table ID for the worksheet? Do I have to put in another step before this one to create the worksheet?

Thanks

 

Phil

Userlevel 7
Badge +8

Hi @philthebass 

 

That is actually a great idea since I dont think you will get the worksheet ID from the previous step, so yes, you can add a step to Create Work Sheet so you can get this new Worksheet ID :) 

 

 

Userlevel 5
Badge +7

Woah @philthebass - looks like you and @MohSwellam were able to get pretty far together in building this Zap and adding the right steps. Anything else you may need from us to make sure your Zap is functioning as expected? 

Userlevel 1

Hi @Rachael S and @MohSwellam ,

I’m running into a problem with Step 6 where I create a Worksheet in the Sheet created in the previous step.

I keep getting this error

Failed to create a worksheet in Google Sheets

There was an error writing to your Google sheet. Request contains an invalid argument.

Troubleshoot error

Also, I think this will create a new worksheet whenever anyone submits the gravity form. I only need to create the worksheet if the Sheet doesn’t exist, purely to create the column headers, before adding the record/row in the last step.

Any suggestions would be greatly appreciated.

Thanks

Phil

Userlevel 7
Badge +8

Hi Phil, 

 

Well I guess then you need to have a master sheet with your customers name/email and the relevant Worksheet and Spreadsheet IDs so you can retrieve it easily instead of creating a new sheet every time

Userlevel 1

Hi @Rachael S and @MohSwellam 

I’ve actually gone backwards with this and can’t figure out what’s broken.

I’ve switched everything over to work with a test environment and started rebuilding this from scratch.

I’ve got to step 5 to check if the file exists and create it if it doesn’t and this looks like this

 

 

And this creates a file but it’s not a Google Sheet,

How do I get the Zap to create this as a Google Sheet?

 

With thanks

 

Phil

Userlevel 7
Badge +8

Hi @philthebass 

 

You’ve gone back too far, we were almost there 😅

 

Anyways, what we need to do is the following: 

 

  1. Undo the part where it creates google drive file if doesn't exist AND set the Should this step be considered a "success" when nothing is found? to Yes
  2. Add a Path by Zapier, one for when it is found and one for not found (it would depend on “_zap_search_was_found_” true or false)
  3. In the path where its true (i.e: it found the Google Sheet file) we will have to search in the Master Google sheet I mentioned above to get the Worksheet ID then use it to update the sheet
  4. In the path where its False we will add a step to create a Spreadsheet and provide the headers you need.  
Userlevel 7
Badge +8

Hiya @philthebass ! Were you able to get this up and running with @MohSwellam ‘s above steps? 

If not, perhaps we could share quick recording for you to reference! Let us know!

Userlevel 1

Hi @Liz_Roberts @Rachael S  @MohSwellam 

Thanks for all your help with this using the Paths that @MohSwellam suggested and that’s working great now and exactly as we need it.

I can now plough on and get the other Zaps built to update the same Sheet.

Thanks again