Created
November 15, 2014 04:47
-
-
Save vinaydotblog/fc8bdca6d5672d4d99e8 to your computer and use it in GitHub Desktop.
Send Google Form Submission to an Email address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Send Google Form by Email v2.1 */ | |
| /* For customization, contact the developer at [email protected] */ | |
| /* Tutorial: http://www.labnol.org/?p=20884 */ | |
| function Initialize() { | |
| var triggers = ScriptApp.getProjectTriggers(); | |
| for(var i in triggers) { | |
| ScriptApp.deleteTrigger(triggers[i]); | |
| } | |
| ScriptApp.newTrigger("SendGoogleForm") | |
| .forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet()) | |
| .onFormSubmit() | |
| .create(); | |
| } | |
| function SendGoogleForm(e) | |
| { | |
| try | |
| { | |
| // You may replace this with another email address | |
| var email = Session.getActiveUser().getEmail(); | |
| // Optional but change the following variable | |
| // to have a custom subject for Google Form email notifications | |
| var subject = "Google Docs Form Submitted"; | |
| var s = SpreadsheetApp.getActiveSheet(); | |
| var columns = s.getRange(1,1,1,s.getLastColumn()).getValues()[0]; | |
| var message = ""; | |
| // Only include form fields that are not blank | |
| for ( var keys in columns ) { | |
| var key = columns[keys]; | |
| if ( e.namedValues[key] && (e.namedValues[key] != "") ) { | |
| message += key + ' :: '+ e.namedValues[key] + "\n\n"; | |
| } | |
| } | |
| // This is the MailApp service of Google Apps Script | |
| // that sends the email. You can also use GmailApp for HTML Mail. | |
| MailApp.sendEmail(email, subject, message); | |
| } catch (e) { | |
| Logger.log(e.toString()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please help. We have been using the code above for several years now with no issues. All of a sudden, it's sending two emails for every response. We did add a couple questions of the form, taking us out to column "AL". Is there some limit set on the rows in a single email?