The "fix" (test_onformsubmit) code you gave, I have to manually run it every time there is new data in the spreadsheet. I was wanting it to automatically send the pdf to email when Form is submitted. Is there a way? Because the manual way runs the code exactly like its supposed to, but I want this as an automatic event so I don't have to do anything.
Asked
Active
Viewed 7.3k times
1 Answers
50
Read Understanding Triggers. This function is an Installable Trigger, so you need to set it up to run when a form is submitted. It's easy - I would have thought a Forms tutorial would have walked through it.
In the Script Editor:
- Choose Edit > Current project's triggers. You see a panel with the message No triggers set up. Click here to add one now.
- Click the link.
- Under Run, select the function you want executed by the trigger. (That's
onFormSubmit()
, in this case.) - Under Events, select From Spreadsheet.
- From the next drop-down list, select On form submit.
- Click Save.
From this point on, the function will be triggered whenever a form is submitted to the spreadsheet.
If you plan to share your script, each recipient will need to repeat these steps.
As an aside, you should change the email setting in your script, so it will work for ANYONE.
var email_address = Session.getActiveUser().getEmail();

Iulian Onofrei
- 9,188
- 10
- 67
- 113

Mogsdad
- 44,709
- 21
- 151
- 275
-
I hate to be such a novice, but I really would like to get this to work so that I can share with my fellow educators. This way once they submit to the form it automatically creates a pdf of their response and sends the pdf as an attachment to their email address. – user2640294 Aug 01 '13 at 12:08
-
Works beautifully! Thanks for your help. – user2640294 Aug 01 '13 at 12:47
-
How do we get the event e, that I can see in many tutorials and even in the documentation, from which we can get other parameters like "e.values", etc..? When I use onFormSubmit(e), it gave me error: "TypeError: Cannot read property "values" from undefined." I also tried: "formSubmitReply(e)", which in turn is not working! – Srichakradhar Jun 17 '15 at 06:54
-
1@Srichakradhar - you're asking a question in a comment on a 2 year old answer; would have been better to first search for an answer (which does exist), then ask a new question (if your search wasn't successful). Looks like you're running the function in the editor, where it's not receiving an event. See [How can I test a trigger function in GAS?](http://stackoverflow.com/questions/16089041/how-can-i-test-a-trigger-function-in-gas). – Mogsdad Jun 17 '15 at 12:51
-
It would be nice if it could use a function from any other script file too. – technazi Feb 01 '19 at 18:35