Coding level: Beginner
Duration: 20 minutes
Project type: Automation with an
event-driven trigger
Objectives
- Understand what the solution does.
- Understand what the Apps Script services do within the solution.
- Set up the script.
- Run the script.
About this solution
If you have various types of content you'd like to offer your audience, you can let users choose what content they receive from you with Google Forms. This solution lets users select the topics they're interested in, then automatically emails them their chosen content.
How it works
The script installs an event-driven trigger that runs each time a user submits a form. With each form submission, the script creates and sends an email from a Google Docs template. The email includes the user's name and the content they selected. The content you offer can be of any type as long as it’s referenced by a URL.
Apps Script services
This solution uses the following services:
- Script service–Installs the event-driven trigger that fires whenever someone submits the form.
- Document service–Opens the Docs template that the script uses to create the email.
- Mail service–Creates and sends the email with the user’s name and content selection.
- Spreadsheet service–Adds a confirmation to the Form responses sheet after the script sends the email.
Prerequisites
To use this sample, you need the following prerequisites:
- A Google Account (Google Workspace accounts might require administrator approval).
- A web browser with access to the internet.
Set up the script
Click the following button to make a copy of the Send curated content spreadsheet. The Apps Script project for this solution is attached to the spreadsheet.
Make a copyIn your copied spreadsheet, click Extensions > Apps Script.
In the function dropdown, select installTrigger.
Click Run.
When prompted, authorize the script. If the OAuth consent screen displays the warning, This app isn't verified, continue by selecting Advanced > Go to {Project Name} (unsafe).
Important: If you run installTrigger more than once, the script creates multiple triggers that each send an email when a user submits the form. To delete extra triggers and avoid duplicate emails, click Triggers
. Right-click on each extra trigger and click Delete trigger.Run the script
- Switch back to the spreadsheet and click Tools > Manage form > Go to live form.
- Fill out the form and click Submit.
- Check your email for an email with links to the content you selected.
Review the code
To review the Apps Script code for this solution, click View source code below:
View source code
Code.gs
Contributors
This sample is maintained by Google with the help of Google Developer Experts.