Apps Script Error: info: undefined

53 views
Skip to first unread message

Michelle P

unread,
Oct 2, 2024, 1:57:43 AMOct 2
to Google Apps Script Community

This script is intended to create a customize PDF file based on the google form responses. This worked a few days back and suddenly it stopped executing.

The object in question ("info") seems to be present but it still returning an error of being undefined

The object, "info", is based on the google sheet header where the google form responses are collected/saved as shown below:

GoogleAppScript_02.png

This is the error:

GoogleAppScript_error.png

And when debugged, it would show that object "info" is undefined:

GoogleAppScript_debugger.png

For reference, this is the script:

function createPDF(info) {
       
  const pdfFolder = DriveApp.getFolderById("1GiY42M3rTq36M9pnUq7Y6RE1qQ8TFN8X");
  const tempFolder = DriveApp.getFolderById("1bkzpVTURICEvcJWemFGaOYTZSdeF_XNj");
  const templateDoc = DriveApp.getFileById("1UfFzcIdG1DCAYpk-NWSiA7bEoz1ZSJXeuV_9-Okw_vg");

  const newTempFile = templateDoc.makeCopy(tempFolder);

  const openDoc = DocumentApp.openById(newTempFile.getId());
  const body  = openDoc.getBody();
  body.replaceText("{Date of Request}",info['Date of Request'][0]);
  body.replaceText("{Requestor}",info['Requestor'][0]);
  body.replaceTest("{Line}",info['Line'][0]);
  body.replaceText("{Cost Centre}", info['Cost Centre (if known)'][0]);
  body.replaceText("{Project Name}", info['Project Name'][0]);
  body.replaceText("{Project Code}", info['Project Code'][0]);
  body.replaceText("{PN}", info['Part Number or Serial Number'][0]);
  body.replaceText("{Reason for Requirement}", info['Reason for Requirement'][0]);
  body.replaceText("{Quantity}", info['Quantity'][0]);
  body.replaceText("{Description}", info['Description'][0]);
  body.replaceText("{Have}", info['Have these products been deemed scrap by the Linelead/Area owner?'][0]);
  openDoc.saveAndClose();


  const blobPDF = newTempFile.getAs(MimeType.PDF);
  const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Requestor'][0] + " " + info['Date of Request'][0]);
  tempFolder.removeFile(newTempFile);  
  return pdfFile;
}

I am no coder and any guidance on this would be greatly appreciated

Fabrice Faucheux

unread,
Oct 12, 2024, 6:00:38 AMOct 12
to Google Apps Script Community
Hello Michelle,

There seems to be a problem with the date of Request. Is it correctly entered in the spreadsheet?

Can you give us some examples?

Ed Sambuco

unread,
Oct 12, 2024, 3:47:22 PMOct 12
to google-apps-sc...@googlegroups.com
Something is wrong with the info parameter you are passing to this routine.  Looking at the code, it is supposed to be an associative array, but I doubt that isw what the program is getting.

"Ce message et toutes les pièces jointes (ci-après le "message") sont établis à l'intention exclusive de ses destinataires et sont confidentiels. Si vous recevez ce message par erreur, merci de le détruire et d'en avertir immédiatement l’expéditeur. Toute utilisation de ce message non conforme à sa destination, toute diffusion 
ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. L'internet ne permettant pas d'assurer l'intégrité de ce message, nous déclinons toute responsabilité au titre de ce message, dans l’hypothèse où il aurait été modifié."

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/4397fef2-d8f8-4923-ae85-fb2ecfd3cef8n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages