Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda