I am trying to use app script with a google forms sheet to populate a docs template which I then send as pdf attachment via Email. I have used the initial template from here: http://www.tjhouston.com/2012/03/merge-info-from-google-forms-to-pdf-document-and-send-via-email/
and made all suggested changes from here: Generate and send pdf through Google Forms to my email address - doesn't send, debugging to no assitance
However, I cannot get it to work. I would highly appreciate any input as i am at my wits end. Weirdly, the logger does not log anything.
var docTemplate = "documentIDhere"; // *** change template ID if new google doc is used***
var docName = "Recruiting Requirement Profile -";
function onFormSubmit(e) {
//Get information from form and set as variables
Logger.log(e)
var Q1 = e.values[2];
var Q2 = e.values[3];
var Q3 = e.values[4];
// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DriveApp.getFileById(docTemplate).makeCopy(docName).getId();
var copyDoc = DocumentApp.openById(copyId);
var copyBody = copyDoc.getBody();
copyBody.replaceText('keyQ1', Q1);
copyBody.replaceText('keyQ2', Q2);
copyBody.replaceText('keyQ3', Q3);
copyDoc.saveAndClose();
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");
var subject = DocName+Q3+"-"+Q1;
var body = "Here is your "+docName+Q3+"-"+Q1;
MailApp.sendEmail("[email protected]", subject, body, {htmlBody: body, attachments: pdf});
// Delete temp file
DriveApp.getFileById(copyId).setTrashed(true);
}
MailApp
andDriveApp
. Please confirm it again. Then, in order to correctly understand your situation, can you provide more information ofI cannot get it to work.
After you modify spelling, if error occurs, please show it. By the way, how do you run your script? – Tanaikeundefined
. – Wencke Harderthe log just tells me undefined.
, I think that you might directly run the function ofonFormSubmit()
at the script editor. If it's so, such error occurs.e
ofonFormSubmit(e)
is an event object. So please install the function as a trigger. By this, when the form is submitted, the function is run and the objecte
is given. – Tanaike