Quickstart: Add-on for Google Forms

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

  1. Create a new Google Form. If you are presented with a welcome screen, give the form a title and choose a theme.
  2. 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.
  3. Delete any code in the script editor and paste in the code below.

    Open code in new window

  4. Create a new HTML file by selecting the menu item File > New > Html file. Name the file "Sidebar" -- this file will describe the look and behavior of the add-on's sidebar.
  5. Delete any code in the new editor tab and paste in the code below.

    Open code in new window

  6. Create a second new HTML file by selecting the menu item File > New > Html file. Name the file "About" -- this file will contain the text that is displayed in the "About this add-on" dialog.
  7. Delete any code in the new editor tab and paste in the code below.

    Open code in new window

  8. Create a third HTML file by selecting the menu item File > New > Html file. Name the file "AuthorizationEmail" -- this is the HTML template used to generate the 'Authorization Required' email notifications.
  9. Delete any code in the new editor tab and paste in the code below.

    Open code in new window

  10. Create a fourth HTML file by selecting the menu item File > New > Html file. Name the file "CreatorNotification" -- this is the HTML template used to generate the form creator email notifications.
  11. Delete any code in the new editor tab and paste in the code below.

    Open code in new window

  12. Create a fifth HTML file by selecting the menu item File > New > Html file. Name the file "RespondentNotification" -- this is the HTML template used to generate the form repondent email notifications.
  13. Delete any code in the new editor tab and paste in the code below.

    Open code in new window

  14. 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

  1. 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.
  2. After a few seconds, a Form Notifications Quickstart sub-menu will appear under the Add-ons menu. (If you chose a different name for your script, that name will appear instead.) Click Add-ons > Form Notifications Quickstart, and in the resulting dialog click Configure notifications.
  3. A dialog box will appear and tell you that the script requires authorization. Click Continue.
  4. A sidebar will appear. 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.
  5. 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 will email 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.
  6. To test the respondent notifications, go back to the sidebar and click the Notify respondents checkbox. The first select box will list 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.
  7. Change the text in the Notification email body text area to say what you what to tell the respondents to your form.
  8. 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. To learn more, check out our add-ons guide.

Learn more

To continue learning about how to extend Google Docs with Apps Script, take a look at the following resources:

Enviar comentarios sobre…