Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
TypeError: Cannot read property 'namedValues' of undefined and 2 other errors

I am very new with Apps Script and I am trying to generate a pdf file upon form submission and send it in an email. I have been trying to fix this for a over a week. I have watched every on tutorial and read numerous articles multiple times to see if I can find where my mistakes are. I am getting 2 errors

  1. TypeError: Cannot read property 'namedValues' of undefined
  2. TypeError: Cannot read property 'Timestamp' of undefined at createPDF

Can someone help me with this? The code that I have so far is below:

function afterFormSubmit(e){

  const info = e.namedValues;
  createPDF(info); 
}

function createPDF(info) {    

const pdfFolder = DriveApp.getFolderById("1tSVmV7-HzZHoYYPBfG1cdImNGuckB2S3")
const tempFolder = DriveApp.getFolderById("1oqyfbwjr21OaPi3rCICgZhIQrU6C4wwA")
const templateDoc = DriveApp.getFileById("18F0iOfZ_Iu71UxjDzRDVjFMRvBA20ATnRX8-E8cy5q0");

const newTempFile = templateDoc.makeCopy(tempFolder)
const OpenDoc = DocumentApp.openById(newTempFile.getId());
const body = OpenDoc.getBody();
   

    body.replaceText("{dt}", info['Timestamp'][0]);
    body.replaceText("{cn}", info['Company Name:'][0]);
    body.replaceText("{jc}", info['Job Code:'][0]);
    body.replaceText("{st}", info['Scope of Work Type:'][0]);
    body.replaceText("{ot}", info['If "Other", please specify:'][0]);
    body.replaceText("{dc}", info['Description of Change:'][0]);
    body.replaceText("{mc}", info['Materials and Cost:'][0]);
    body.replaceText("{lc}", info['Labor Cost:'][0]);
    body.replaceText("{tx}", info['Tax Cost:'][0]);
    body.replaceText("{tl}", info['Total:'][0]);
    OpenDoc.saveAndClose();

  const blobPDF = newTempFile.getAs(MimeType.PDF);
  const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Job Code:'][0] + " " + info['Company Name:'][0]); 
  tempFolder.removeFile(newTempFile);
}
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!