Thursday 14 February 2019

Save email to Drive add-on - make the copy

Overview blog post.

The following Google Apps Script code makes the physical copy of the email and stores it as a PDF in the relevant Google Drive student folder.

It starts by getting the ID of the Google doc template file which will be duplicated and its tags replaced with fields from the email message. As we passed in a number a parameters from the showCard function we can now assign these to variables (saving us time by not having to query the whole spreadsheet data again):
var userId = e.parameters['userId'];
Logger.log('userId is: ' + userId);
Next we run the getCurrentMessage function which does so via an event object and passes it back through to the makeTheCopy function for interrogating. So now the subject, date, from, etc can be assigned to variables as well as 'getPlainBody' for the email contents.

A suitable date is created for naming the saved email - in this example the format YYYY_MM_dd was requested (here is a blog post with a similar process). We 'getFolderById' using the value from the spreadsheet for the student then make a copy of the Google doc and update the tags (process described in this blog post).

The final part of this script creates a PDF version of the Google doc and saves it in the students Drive folder (blog post detailing this process). Before then running the finishedCard function.

No comments:

Post a Comment