Automate Based on Google Form Response

Learn how to automate actions based on Google Form responses using Google Apps Script, including sending customized emails based on the city selected in the form.

So you want to create an automation based on the response in your Google form . So let's create a Google form . We're getting some orders. And in our case, let's do different automations based on which city it is going to. Do tools create a new form. We'll get an item. We need to know their city and we need to know their email address. Maybe we have some follow-up to do based on this particular city. Let's create a multiple choice option here. New York, Chicago, Miami, and Seattle. And let's make sure we publish this. And we have a basic form. We have city here that basically based on the response, which one of these we want to do something different. So let's go back to our sheet. Go to extensions appcript and start building out an automate. I'm going to create an function called email

me. And it's going to have an event. This event variable here is something we can call E if we want, but it's all of the form information submitted. How does that work? I'm going to show you in a quick second, but let me write a little bit of a function here like send an email owner city submitted body will create the body from the form. Let's say we have a variable owner is just spreadsheet get this spreadsheet get the owner and get their email address. This is a programmatic way to get my own email address. But if you're using the sheet or creating the sheet for someone else, it's very nice to get their email of the owner of the spreadsheet and send

them an email. Now, let's create a very simple body here, just a couple words. But this city, we're going to get the name of the city, the response of city. So, we can get that from the variable here, E. So, E.named values , and in square brackets, put city in a quote. So, we'll add that to the subject. And now that I have some basic function created, I'm going to create that trigger that I mentioned earlier. I'm going to go over to the left side called bottom right. Click add trigger . I'm going to choose which function to run, which is the only one right now, but if you had other functions , you can choose it. From spreadsheet is the event source and on form submit is the event type say may have to authorize it at this moment. That's one reason also why I wait to

write a little bit of the script so that it authorizes the right items. Now that I have my automation set up, I can start testing this automation by filling out some information. Item one, let's say shikham buddies email atmail.com. Let's and if we get any errors, it'll show up here on executions. You can see this function is trigger and I have an email with the city Chicago here. So now we have a function here where we know exactly which city is being submitted. So now we can create a little bit of logic that says if it's Chicago do something. If it's something else do something else. For example, maybe we need to CC someone else on an email. If

it's Chicago versus New York. So if and in parentheses city is equal to now this is two equal signs Chicago then in curly brackets we're going to do something. Maybe again we add a CC to here. So let's add some options. Options variable options equals and in curly brackets we'll do CC. And if the city is Seattle, we'll do something else. Maybe we just send the email with no CC. So let's go back to our form. Submit another response item two. Let's do Seattle example. And let's submit another response. Item three, Chicago email. And we can see our Seattle one

has no C. And our Chicago one does have a CC carbon copy. Fantastic. So that's some basic logic functionality based on what is the answer to a Google form response. You're watching Better Sheets here on YouTube. Make sure you check out this video or this video and subscribe right now to get more tips, tricks, how-tos, get more out of your Google Sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is going to be your next Google Sheet.