Complete the steps described in the rest of this page, and in about ten minutes you'll have created a Google Forms add-on that uses triggers to send an email when a user responds to the form. To see what the add-on looks like when it's finished, just install Form Notifications from the Google Forms Add-ons store.
Set it up
- Create a new Google Form. If you are presented with a welcome screen, give the form a title and choose a theme.
- From within your new form, click the More more_vert menu and select Script editor.... If you are presented with a welcome screen, click Blank Project.
- Create a new HTML file by selecting the menu item File > New > HTML file.
Name this file
sidebar
(Apps Script adds the.html
extension automatically). - Repeat the previous step to create one more HTML file named
about.html
. - Replace the content of those files with the following content, respectively:
code.gs
sidebar.html
about.html
- Create three more HTML files:
authorizationEmail.html
,creatorNotification.html
, andrespondentNotification.html
. Replace the content of those files with the following content, respectively:
authorizationEmail.html
creatorNotification.html
respondentNotification.html
- Select the menu item File > Save all. Name your new script "Form Notifications Quickstart" and click OK. (The script's name is shown to end users in several places, including the authorization dialog.)
When you have completed this process, you will have a project with 1 script file and 5 HTML files.
Try it out
- Switch back to your form. Using the Add item select box, add a text question to your form. Under Question Title, enter 'Email Address' and click Done. You can create other form items if you like.
- After a few seconds, a Form Notifications Quickstart sub-menu will appear under the Add-ons extension menu. (If you chose a different name for your script, that name appears instead.) Click Add-ons > Form Notifications Quickstart, and in the resulting dialog click Configure notifications.
- A dialog box requesting script authorization appears. Click Continue.
- The add-on sidebar then appears. To test it, click the Notify me check box and enter your email address. Also set the Send notifications after box to '1'. Click Save.
- Click Preview so that you can submit a response. From here, enter some information into the form elements and click Submit. If you have done everything correctly, the add-on emails you a short notification saying someone has responded to your form. Had you not changed the Send notifications after every box, the add-on would have waited until the form had 10 submissions (the default) before emailing you a notice.
- To test the respondent notifications, go back to the sidebar and click the Notify respondents checkbox. The first select box lists the question titles for each text question in your form. Choose the question you labeled 'Email Address'. If the 'Email Address' option does not appear, make sure you've added a text item to your form named 'Email Address' (as stated in Step 1), and reopen the sidebar by clicking Add-ons > Form Notifications Quickstart, and in the resulting dialog clicking Configure notifications.
- Change the text in the Notification email body text area to say what you what to tell the respondents to your form.
- Go back to the form, fill out another submission and click Submit. If you have done everything correctly, two emails should be sent this time—one to the form creator and one to the form respondent. The form creator email address is the one you entered into the sidebar directly; the form respondent email address is what the respondent supplied in the 'Email Address' question.
Publish
Since this is an example add-on, our tutorial ends here. If you were developing a real add-on, the last step would be to publish it for other people to find and install.
Learn more
To continue learning about how to extend Google Docs with Apps Script, take a look at the following resources: