I'm just newbie in JavaScript, sorry for my poor english. I follow coding from somepeople . I try many time to understand and can not fix this problem (Didn't find answer in his post and comment too.). Here is original code. Log's say
TypeError: Cannot read property 'namedValues' of undefined".
Then I have 2 questions.
How to Fix this error ? (This function i trying to create) error in line 3.)
Can modify this code autorun after New row added in google spreadsheet (Sample : I have 2 records, when i insert another row (1 new record) by other way etc. typing via web application (not form), this script automatically run by detect new row.)
Modified Q2 2021/04/06
function AfterFormSubmit (e) {
const info = e.namedValues(info);
const pdfFile = createPDF(info);
const entryRow = e.range.getRow();
const ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet");
ws.getRange(entryRow, 6).setValue(pdfFile.getUrl());
ws.getRange(entryRow, 7).setValue(pdfFile.getName());
function createPDF(info) {
const pdfFolder = DriveApp.getFolderById("XXXX");
const tempFolder = DriveApp.getFolderById("XXXX");
const templateDoc = DriveApp.getFileById("XXXX");
const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
body.replaceText("{fn}", info['First Name'][0]);
body.replaceText("{ln}", info['Last Name'][0]);
body.replaceText("{addr}", info['shipping address'][0]);
body.replaceText("{qty}", info['Quantity Required'][0]);
openDoc.saveAndClose();
const blobPDF = newTempFile.getAs("application/pdf");
const pdfFile = pdfFolder.createFile(blobPDF).setName(info['First Name'][0]);
tempFolder.removeFile(newTempFile);
return pdfFile;
}