How to create a Google Form with conditional email notifications using Google Apps Script

I was recently tasked with creating a Google Form for teachers to request technology purchases from the district. The goal was to have the principal of each school receive an email notification when a teacher in their building submitted the form.

I knew you could set up basic email notifications in Google Forms, but I wasn’t quite sure how to customize the notifications so only specific people were notified based on the form responses. Of course, we could always create separate Google Forms for each building, but that’d be a lot to manage.

After a little digging, troubleshooting, and consulting with ChatGPT, I was able to get it working using Google Apps script.

I’ve detailed the process below in case you’ve found yourself on a similar quest. Don’t worry if you don’t have a ton (or any) experience with Google Apps Script. This post will walk you step by step through the process. Here we go!

 
 

Step 1: Create a Google Form

  1. Go to Google Forms: https://forms.google.com/

  2. Click on the "Blank" option or choose a template to start with.

  3. Add questions and customize your form as needed.

  4. Make sure to include a dropdown question that will determine the recipient of the email notification (e.g., School Building).

STEP 2: Connect the Google Form to a Google Sheet

  1. In your Google Form, click on the "Responses" tab.

  2. Click on the Google Sheets icon (green square with a white cross) to create a new spreadsheet or link to an existing one. Follow the prompts to complete the connection.

Step 3: Open Google Apps Script

  1. Open the connected Google Sheet.

  2. Click on "Extensions" > "Apps Script."

step 4: Add and Customize the Script

  1. Remove any existing code in the "Code.gs" file.

  2. Copy the script provided at the end of this post and paste it into the "Code.gs" file.

  3. Follow the directions on the script to customize as needed.

  4. Click Save Project (the floppy disc icon) on the menu bar.

Step 5: Set Up the Trigger for the Script

  1. In the Apps Script editor, click on the clock icon on the left-hand side to access the "Triggers" page.

  2. Click the "Add Trigger" button in the bottom-right corner, or the “Create a new trigger” text in the center of the page.

  3. Set up the trigger with the following options:

    • Choose which function to run: onFormSubmit

    • Choose which deployment should run: Head

    • Select event source: From spreadsheet

    • Select event type: On form submit

  4. Click "Save” and follow the permission prompts.

Step 6: Test Your Form and Script

  1. Fill out and submit your Google Form.

  2. Check the recipient's email to ensure they received the custom email notification.

And that's it! You've successfully created a Google Form with custom email notifications. 🎉


Google Apps Script

 
 

Below is the Google Apps Script you can use to create our own Google Form with conditional email notifications.

If you’re having trouble viewing the embedded Google Doc below, click here to open it in a new window.

If you are having difficulty getting the script to work, please review the steps above to make sure you’ve saved the script and set up the trigger properly. I am not an expert in Apps Script and am unable to help troubleshoot individual cases, but I recommend copying your code into something like ChatGPT and asking it to identify any errors that may have been introduced when editing. ChatGPT’s coding abilities aren’t perfect by any means, but I’ve discovered that it’s a great troubleshooting partner!

 

Did you find this post helpful? Let me know in the comments. I’d love to know how you used this script!

Previous
Previous

Carousel Writing: An engaging, no-prep ELA classroom activity

Next
Next

A Teacher’s Guide to Using ChatGPT: Essential Tips Every Teacher Should Know