0

I am currently working on creating a script that would do the following:

  1. take a Google Forms submission
  2. store it in Google Sheets spreadsheet
  3. convert the data submitted to a PDF using Google Doc template
  4. store the PDF in Google Drive and add a link to the spreadsheet
  5. email the PDF as attachment to the person that submitted the Google Form.

Currently, I am in step 3 which I keep getting the following after you submit a form "TypeError: Cannot read property "Company" from undefined. (line 16, file "Code")". The "Company" is the title of the headers in my google sheet which from one of the questions in my form. I double check the name, white spaces and other things that could affect it but I still keep getting this error. I try doing it one by one with the others and I get the same error or I get

TypeError: Cannot read property '0' of undefined".

function formSubmit(e) {
  const info = e.name;
  createPDF(info);
}

function createPDF(info){

  const pdfFolder = DriveApp.getFolderById("1Q9pB4n14m9VEikouQ-_WWx5LIAgDxhAL");
  const tempFolder = DriveApp.getFolderById("14iJEpwsb1KpeIYdcmQGuakyN9DmJXa9U");
  const templateDoc = DriveApp.getFileById("1DiCDrHhqxVWaVn8uxx3sExM3dl45VPLKxFmqy6xL9oc");

  
const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
  body.replaceText("{C}", info['Company'][0]);
  body.replaceText("{pName}", info['Print Name '][0]);
  body.replaceText("{Date}", info['Date'][0]);
  body.replaceText("{lName}", info['Last Name'][0]);
  body.replaceText("{fName}", info['First Name'][0]);
  body.replaceText("{mName}", info['Middle Name'][0]);
  body.replaceText("{dName}", info['Department Name'][0]);
  body.replaceText("{emName}", info['Engagement Manager Name'][0]);
  body.replaceText("{srAnswer}", info['Your Services and Responsibilities'][0]);
  body.replaceText("{listAanswer}", info['"LIST A": '][0]);
  body.replaceText("{listBanswer}", info['"LIST B":'][0]);
  body.replaceText("{listCanswer}", info['"LIST C":'][0]);
    
openDoc.saveAndClose();
    
  
  
  
  
 const blobPDF = newTempFile.getAs(MimeType.PDF);
 const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Print Name'][0] + " " + "Completed Onboarding Packet");
 tempFolder.removeFile(newTempFile);
    
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
  • probably means `e.name` is `undefined` ... looks like `e` is an event, event's don't normally have a `.name` property – Jaromanda X Oct 16 '20 at 03:31
  • even if events did have a property called name ... why would a property called name have those particular properties, all of which are arrays ... – Jaromanda X Oct 16 '20 at 04:00
  • Does this answer your question? [How can I test a trigger function in GAS?](https://stackoverflow.com/questions/16089041/how-can-i-test-a-trigger-function-in-gas) – Rubén Oct 10 '22 at 14:44

0 Answers0