Gravityforms pushing to new Google Sheets according to post name, and Checking if it already exists
Hoping a guru finds this a fun challenge.
We are taking bids from contractors for deck building. I’m posting jobs to contractors who have access to see these jobs and bid on them. I have a singular form on each job posting which auto pulls lots of data including the post title which has a job number, city, and state.
From there, I can get Zapier to recreate via Google Sheets template and name the Sheet exactly the job number, etc.
What I’m looking to do is make Zapier check to see if a spreadsheet already exists. The first form submission will create the Google Sheet and fill in the info but the second one will check to see if it exists, and if so just add that bid information and not create a new sheet document.
Here’s the rundown:
Contractor fills out the gravityform
GF autopopulates hidden fields and is readied for Zap
Zap creates the new Google Sheet and dynamically names based on Post name, fills bid into first row.
Another contractor fills out the gravityform for the same job.
Zapier checks and sees that the Sheet already exists - skips the creation of new sheet and instead, fills that bid data into 2nd row.
Rinse/repeat
My problem is that I can’t figure out how to tell Zapier to check for a Sheet that doesn’t exist yet until that first form submission. Then how to make that same zap see that it’s previously been created. I can have it check after the Sheet has been created but I can’t figure out how to tell it to check for a name in the Zap if the form hasn’t been filled out yet in order to create the new Sheet.
Any help would be appreciated! Thanks.
Page 1 / 1
Hey @DanP, welcome to the Community!
Ah, yes Google Sheets doesn’t have the sort of “find spreadsheet” action you’d need but you could potentially use a Google DriveFind a File action to look for the file. Then use Paths by Zapier to have the Zap either create the spreadsheet if it didn’t find it and add the bid to it or, if it already exists then just add a new row to the existing spreadsheet.
You’d want to set up the paths to check whether the _zap_search_was_found_status field output by the Google Drive action is either true (meaning it found an existing spreadsheet) or false (meaning it didn’t find one).
Can you give that a try and let us know how it goes?
Thanks @SamB. How would I dynamically have it check for the name since the new spreadsheet is dynamically named based off of data coming from the Gravity Form (form title + name of page the form is on). This form will be on multiple pages and will grab the title of the form and title of page as a portion of the new Google Sheet name.
How would I set up a check for a dynamically created name? I seem to only be able to check for a sheet that was already created. This data will be held in the GF data.
Thanks!
@DanP
Are the those items in the post from Gravity Forms? The form name and page title?
If so you could manipulate the data in a formatter or code block to give you the filename. And use that to run the search.
A code block to combine them to create/recreate the sheet name might be easiest. Assuming the data is there.
Perhaps even a sheet with the created filenames on it may be another way.
Its a tough one as you don't know the name of you are searching for..
Hi @Badger - Yes, gravity form collects the Form Name and combines it with the Job Title (basically the wordpress post title) so it looks like this: “Form Title”: “Job Title” Job title is essentially {embed_post:post_title} in Gravityform and is collected, ready to output however needed.
Would this be a way to get it to work: To add the filename first as an entry in a different spreadsheet upon submission, then in the next step, check to see how many times that entry exists in the spreadsheet. If one entry with that name exists, then create a new spreadsheet but if more than one of that entry, then add the rest of the info into the existing Google sheet?
@DanP
First thing I would try is replicating that entry into the find filename box for the search.
If it finds the sheet you can then continue to your Exists path.
If you need to provide it as a string it would be very easy with a code block and python.
I did think having a sheet of created names would be a good idea. I was wondering how to get a count of the search but if the name exists then its highly likely the sheet does too.
If you need a hand with the code let me know as it wouldn't take long and the AI could probably do it straight away.
Help with a code block would be amazing if you’re up for it. Thank you.
@DanP
Here’s an example of creating a full name from the first_name and last_name columns of a google sheet.
Start by adding the code block and then running python.
Next write the code.
When testing, you get the the output as one string.
Here is the code block.
# get the Input data firstname = input_data 'first_name'] lastname = input_data 'last_name']
# create an F String full_name = f'{firstname} {lastname}'
return {'Full Name': full_name}
Let me know if this makes sense.
I have found ChatGPT is very good for helping with the code block. When writing the prompt insure you state that you are using python in Zapier and can only use the standard library and requests. It will ensure it won’t try to import packages you can’t use.
Hope this is useful.
Hi @DanP,
I just came across your post here and wanted to check in here to see how you’re getting on. Were you able to follow @Badger suggestion here?
Please note that Code by Zapier is an advanced feature so our support for that is limited.
Hey @ken.a - I appreciate the time @Badger spent on my issue - thanks Badger. However I’m not sure it’s going to help my issue with checking to see if the google sheet has already been created.
Thank you
Hey @DanP, sorry for the delay in my reply here!
How would I set up a check for a dynamically created name? I seem to only be able to check for a sheet that was already created. This data will be held in the GF data.
The same way you’d create the new spreadsheet with the same name—in the Filename field in the Find a File (Google Drive) action you could select the same fields you did in that Create Spreadsheet (Google Sheets) action:
Then, that would allow the Find a File action to find the existing spreadsheet if it exists, as long as the selected fields exactly match the file naming convention of the existing spreadsheets.
Would this be a way to get it to work: To add the filename first as an entry in a different spreadsheet upon submission, then in the next step, check to see how many times that entry exists in the spreadsheet. If one entry with that name exists, then create a new spreadsheet but if more than one of that entry, then add the rest of the info into the existing Google sheet?
To check how many entries mention that same file name you’d want to use a Lookup Spreadsheet Rows (Google Sheets) search action and in the Spreadsheet field, use the custom value option and select the ID of the spreadsheet file that the Find a File action found. And in the Lookup Value field, map the relevant fields from the GravityForms trigger depending on what you’re looking for a match for. To know the exact number of spreadsheet rows found by that Lookup Spreadsheet Rows action you could use the approach outlined here:
And then you could use paths to carry out actions based on the number of rows that were found.
Hope that helps. Keep us updated on how you get on, want to ensure you’re all set!
@DanP
The code can be amended to format the filename string. If the formatter is an issue in creating the string you can combine the elements from gravity forms to get whatever string you need.
I prefer this short code blocks as they tend to fit my brain better. I can collate all the information I need to pass on to other steps and not get lost. It costs a task but my zap runs aren’t usually very high.
Thanks for the help guys. I will let you know how it goes.
Hi @DanP,
Just keep us on the loop so we can troubleshoot further if needed. Thank you.
@SamB @JammerS @ken.a @Badger
I’m almost there and can get it done with existing Zapier components but need some help. Is there a way I can share access with any of you to take a look?
Here’s the rundown:
Gravity form is submitted - pulls the “Job Name” from WordPress post title along with lots of other info.
In a side Google Sheet, named “ZAP Counting Submissions Only” that job name is added as a row to be used for comparing later.
Look for repeats of that job name:
If only 1 of that name exists, follow the path to the right to create a new spreadsheet based on the job name and fill the rest of the data into row as I’ve set up.
If more than 1 of that name exist, then that means that 3.1 has already been done, therefore follow the path to the left and enter the data as a row into the sheet that already exists.
As you can see from the image, I have most of it set up. The paths work, but need to get #3 and #4 working so the zap can do 3.1 or 3.2 above.
Thanks!
Great to hear from you @DanP!
Is there a way I can share access with any of you to take a look?
Unfortunately not, us folks here in the Community don’t have access to do that—only the Support team would have the necessary access to view your Zaps.
As you can see from the image, I have most of it set up. The paths work, but need to get #3 and #4 working so the zap can do 3.1 or 3.2 above.
The Get Many Spreadsheet Rows action will pull a number of rows from the spreadsheet and return a total Count of how many rows out of that number it was looking for that it found, however it won’t be able to only look for a specific job name. Instead you’d need to use a Lookup Spreadsheet Rows action and set it to look for a specific job name. For example:
That set up searched the Name column for all rows in the spreadsheet and was able to find the two rows in my spreadsheet that had the name Batman used:
From there you’d need a way of counting the number of rows it found so that you can have the paths check if the number of rows is over a certain amount. Looking closer at the example guide I shared previously that appears to only work for numerical values—sorry about that! So in this case you’d need to use a Code action instead as per this alternative guide:
I tested it in my Zap and it was about to count the number of items successfully.
I used the same code that was used in the guide:
let Set = inputData.Set; let SetCount = 0; // defaults the Set Count to 0
// If Set exists if (Set) { Set = Set.split(","); // creates array by splitting Input Data Variable at commas SetCount = Set.length; // determines the length of the array (aka number of array items) }
output = s{SetCount, Set}];
The set up looked like this:
And that correctly outlut the number of items as 2
From there the Paths can check if the value in that Set Count field is greater than 1 or less than 2.
Path A setup:
Path B setup:
Can you give that a try and let us know how you get on?
Getting close - one hiccup. In your example of “Batman” - I can see how that works but in my case we’re doing something like the following: “Job# 12345, City, State” which then is parsed as multiple sets because of the comma. I’m going to rework the job name so no commas exist and revisit step #4.
Got those to push through, do the count, and path selection… very nice! THANK YOU
One final question now to finish:
I understand this is probably super easy, but once the path is selected, how do I tell the zap to enter info into the correct spreadsheet?
Left path - Sheet exists, just needing to add a row of content into it: I’ve found the file that already exists - how do I now tell Zapier to add to that specific file? All I can find are options to add to specific sheets…
Right path - Sheet didn’t exist, it’s been created successfully, how to add row of content into it: Pretty much the same question. I’ve now created a new sheet - how do I zap in the data from gravityforms?
Yay! I’m so pleased that helped, @DanP!
I’ve found the file that already exists - how do I now tell Zapier to add to that specific file? All I can find are options to add to specific sheets…
To select the spreadsheet that was found by the Google Drive action you’d need to first select the Custom value option on the Spreadsheet field:
Then select the ID field from that Google Drive action:
Pretty much the same question. I’ve now created a new sheet - how do I zap in the data from gravityforms?
Similarly, you’d need select the Custom value option on the Spreadsheet field:
And then select the ID field from the Google Sheets action that creates the spreadsheet:
That will allow you to dynamically select the spreadsheet that the new row needs to be added to.
Hope that helps clarify the process. Let me know if you have any questions—I’m happy to help further if you get stuck at all.
Thanks @SamB - but after that step, to continue I need to choose a value for the Worksheet which is empty and I can’t select or continue...
Ah I see, @DanP. Well, if the worksheet isn’t available to select then you can manually enter it’s ID—the default/first worksheet on a Google Sheets spreadsheet always has an ID of 0.
To dynamically select the worksheet on the Create Spreadsheet Row actions (in each path) you’ll want to choose the Custom value option again and then type in 0 like so:
Can you try that and let us know whether it works as hoped?
Ended up not using custom on that last portion as Zapier was holding the data in memory and I pulled ID. Thank you for all of your help!
That's awesome, @DanP! A huge thank you to everyone who lent a hand here! This thread is fantastic!
If you have any other questions, please don’t hesitate to reach out to the Community. We’re always happy to help!