Created
April 26, 2013 09:34
-
-
Save twotix/5466081 to your computer and use it in GitHub Desktop.
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
| // TJ Houston tjhouston.com (tj@tjhouston.com) | |
| // Bus Conduct Report | |
| // Get template from Google Docs and name it | |
| var docTemplate = ""; // this is what you want to change for your version | |
| var docName = "BusConductReport"; | |
| // When Form Gets submitted | |
| function onFormSubmit(e) { | |
| //Get information from form and set our variables | |
| var email_address = ""; // People who should get PDF | |
| var full_name = e.values[2]; | |
| var incident_date = e.values[5]; | |
| var grade_level = e.values[4]; | |
| var bus_number = e.values[6]; | |
| var violations = e.values[10]; | |
| var explanation = e.values[11]; | |
| var drivers_coa = e.values[12]; | |
| // Get document template, copy it as a new temp doc, and save the Doc’s id | |
| var copyId = DocsList.getFileById(docTemplate) | |
| .makeCopy(docName+' for '+full_name) | |
| .getId(); | |
| // Open the temporary document | |
| var copyDoc = DocumentApp.openById(copyId); | |
| // Get the document’s body section | |
| var copyBody = copyDoc.getActiveSection(); | |
| // Replace place holder keys,in our google doc template | |
| copyBody.replaceText('keyFullName', full_name); | |
| copyBody.replaceText('keyTodaysDate', incident_date); | |
| copyBody.replaceText('keyGradeLevel', grade_level); | |
| copyBody.replaceText('keyBusNumber', bus_number); | |
| copyBody.replaceText('keyViolations', violations); | |
| copyBody.replaceText('keyExplanation',explanation); | |
| copyBody.replaceText('keyDriverCOA', drivers_coa); | |
| // Save and close the temporary document | |
| copyDoc.saveAndClose(); | |
| // Convert document to PDF | |
| var pdf = DocsList.getFileById(copyId).getAs("application/pdf"); | |
| // Attach PDF and send the email | |
| var subject = "Bus Conduct Report"; | |
| var body = "Here is the Bus Conduct form for " + full_name + ""; | |
| MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf}); | |
| // Delete temp file | |
| DocsList.getFileById(copyId).setTrashed(true); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment