I used the Google Forms tutorial to set up form data to be combined into a PDF file and then sent by email. When trying to run the script:
The following error message appears:
TypeError: Unable to read property values ββfrom undefined. (line 11, file "Code")
I do not know how to fix this problem. I searched the Internet for an answer. Here is a copy of the script. I noted two lines where the script gives an error:
var docTemplate = "1ZSqmId2BBjtz6PmgQEmusjnkHGsFKD1CBSq0rrQk6Kc"; var docName = "TestCertificate"; // When Form Gets submitted function onFormSubmit(e) { //Get information from form and set our variables var email_address = "EMAIL@example.com"; //**(THIS IS WHERE THE ERROR IS OCCURRING ON THESE 2 LINES BELOW!)** var full_name = e.values[2]; var Activity = e.values[3]; // Get document template, copy it as a new temp doc, and save the Doc's id var copyId = DocsList.getFileById(docTemplate) .makeCopy(docName+' for '+full_name) .getId(); // Open the temporary document var copyDoc = DocumentApp.openById(copyId); // Get the document's body section var copyBody = copyDoc.getActiveSection(); // Replace place holder keys,in our google doc template copyBody.replaceText('keyFullName', full_name); copyBody.replaceText('keyActivity', Activity); // Save and close the temporary document copyDoc.saveAndClose(); // Convert document to PDF var pdf = DocsList.getFileById(copyId).getAs("application/pdf"); // Attach PDF and send the email var subject = "Report"; var body = "Here is the form for " + full_name + ""; MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf}); // Delete temp file DocsList.getFileById(copyId).setTrashed(true); }
Here are the links to the form and certificate that I tested.
google-spreadsheet google-apps-script
user2640294 Aug 01 '13 at 2:25 am 2013-08-01 02:25
source share