To view the triggers for the current scripts, click on the aptly named Current script's triggers in Resources.
|Resources > Current script's triggers|
|If you've not set any up yet you'll see this. Click the link!|
|We want a Spreadsheet trigger - specifically from a form submit event|
|While you're here, make sure you set up Notifications|
Now you've set up a trigger which will cause your function to run every time somebody submits your form! Let's test it out with a function which will email us a copy of their submission as soon as they submit it. Note; in the spreadsheet of form responses you can opt to receive email notifications every time a form is submitted simply by checking a box (Tools > Notification rules... > A user submits a form) however this is plain notification and doesn't add any detail from the submission.
Before this script will work we need to authorise the script to send email from our account. Copy and paste the script in to your project, make sure you've set up your triggers correctly and click on the save button. Now, click on the Run button (Play icon) and you'll see an authorisation window pop up. You'll need to click the authorise button if you're happy for the script to send email on your behalf.
Notes on the function
- "\n" indicates a new line - helpful to make our email easier to read.
And here's the result:
|The fruit of our labour: an automatically generated email|