Created
October 9, 2013 14:48
-
-
Save jccarlin56/6902503 to your computer and use it in GitHub Desktop.
Create and share a personalized Google Doc that shows the user's itinerary. @param {Object} user An object that contains the user's name and email. @param {String[][]} response An array of data for the user's session choices.
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
| /** | |
| * Create and share a personalized Google Doc that shows the user's itinerary. | |
| * | |
| * @param {Object} user An object that contains the user's name and email. | |
| * @param {String[][]} response An array of data for the user's session choices. | |
| */ | |
| function sendDoc_(user, response) { | |
| var doc = DocumentApp.create('Conference Itinerary for ' + user.name) | |
| .addEditor(user.email); | |
| var body = doc.getBody(); | |
| var table = [['Session', 'Date', 'Time', 'Location']]; | |
| for (var i = 0; i < response.length; i++) { | |
| table.push([response[i][0], response[i][1].toLocaleDateString(), | |
| response[i][2].toLocaleTimeString(), response[i][4]]); | |
| } | |
| body.insertParagraph(0, doc.getName()) | |
| .setHeading(DocumentApp.ParagraphHeading.HEADING1); | |
| table = body.appendTable(table); | |
| table.getRow(0).editAsText().setBold(true); | |
| doc.saveAndClose(); | |
| // Email a link to the Doc as well as a PDF copy. | |
| MailApp.sendEmail({ | |
| to: user.email, | |
| subject: doc.getName(), | |
| body: 'Thanks for registering! Here\'s your itinerary: ' + doc.getUrl(), | |
| attachments: doc.getAs(MimeType.PDF), | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment