Skip to content

Instantly share code, notes, and snippets.

@jccarlin56
Created October 9, 2013 14:48
Show Gist options
  • Select an option

  • Save jccarlin56/6902503 to your computer and use it in GitHub Desktop.

Select an option

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.
/**
* 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