Chapter 9. Mash Up

Directing Email Using Google Forms

Google Forms are a very convenient way to quickly get information into a spreadsheet. Add some Google Script and you can turbo charge that form to send email notifications, generate other data in the spreadsheet, and all those things you might want to do when getting data from a form.

In this section you will learn the basics of getting form information into a Google Script and sending an email depending on a selection from a drop down list in the Google form.

Highlights:

  • Google Forms

  • EmailApp

  • Event Triggers

Open up a Google spreadsheet and start creating a form. The example we will use is for routing inquiries to the right department: Sales or Service. Figure 9-1 shows the form editor and the drop down box selection.

Google forms can be inserted into most websites and emailed
Figure 9-1. Google forms can be inserted into most websites and emailed

After creating the form you can return to the spreadsheet to see the form fields have become columns in the spreadsheet. See Figure 9-2.

Note the timestamp is automatically added
Figure 9-2. Note the timestamp is automatically added

Now open the Script Editor (Tools➝Script editor).

You can delete the default function and start the script with global variables (outside any function) that will contain the email addresses for the correct department.

var sales = 'sales@example.com'; var service = 'service@example.com'; ...

Get Google Script: Enterprise Application Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.