I have a google script to use a form submission to fill out a document, then convert it to a PDF and save the PDF, then email it out to 2 emails. One is to the respondent whos email is on the google worksheet and one to the hard coded email address. The trigger is working, the document gets filled out and save as a PDF to the correct folder. I have verified all the links to the appropriate forms, doc, and cells are correct. But it will not send either email. I am new to Google Script so can use any and all help.
function afterFormSubmit(e) {
const info = e.namedValues;
const pdfFile = createPDF(info);
sendEmail(e.namedValues['Email Address'][0], pdfFile);
sendEmail2(e.namedValues['Name'][0], pdfFile);
}
function sendEmail(email,pdfFile){
GmailApp.sendEmail(email,"Cutting Edge Renovation and Painting, LLC - Acknowledgement Form Completed", "Please find a copy of the Cutting Edge Renovation and Painting, LLC Acknowledgement form you completed for your records.",{attachments:[pdfFile],
name: 'Cutting Edge Renovation and Painting, LLC'
});
}
function sendEmail2(ClientName,pdfFile){
GmailApp.sendEmail("[email protected]","Cutting Edge Renovation and Painting, LLC - Client Completed the Acknowledgement Form", ClientName & " " & "has completed the Acknowledgement form",{
attachments:[pdfFile],
name: 'Cutting Edge Renovation and Painting, LLC'
});
}
function createPDF(info){
const pdfFolder = DriveApp.getFolderById("1N2QTvSJgRMtBx7TzCIKUWc6o3JOhfuGU");
const tempFolder = DriveApp.getFolderById("1WpbEOn_zH1IdvA_PkvxeDPnMXJVVMWQj");
const templateDoc = DriveApp.getFileById("1QMHSL1CFb_2srVDd1YZlQEmGMTx0sHm7NGjWBZpnccE");
const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
body.replaceText("{Name}", info['Name'][0]);
body.replaceText("{Address}", info['Job Address'][0]);
body.replaceText("{Photo}", info['Photo Release'][0]);
body.replaceText("{Access}", info['Home Access'][0]);
body.replaceText("{Parking}", info['Parking'][0]);
body.replaceText("{Parking2}", info['Parking Permit'][0]);
body.replaceText("{Signature}", info['Signature'][0]);
body.replaceText("{Phone}", info['Phone Number'][0]);
body.replaceText("{Date}", info['Timestamp'][0]);
openDoc.saveAndClose();
const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Name'][0]);
}
const pdfFile = createPDF(info);
infunction afterFormSubmit(e)
will only runfunction createPDF(info)
(which creates the files) but will not return the pdf becausefunction createPDF(info)
has no return value.console.log(pdfFile)
afterconst pdfFile = createPDF(info);
? I think it will return undefined.