【发布时间】:2020-12-22 12:27:15
【问题描述】:
请帮我解决以下错误。
TypeError:无法读取未定义的属性“namedValues”
因为我是 Google Apps 脚本的新手。我想生成 PDF 并通过他的电子邮件 ID 发送给请求者。请在下面查看我的脚本并提出建议。
function afterformsubmit(e){
const info = e.namedValues;
createPDF(info);
}
function createPDF(info){
const pdfFolder = DriveApp.getFolderById("1nV1zSSJfBND0ao9NufmIOEa_ocO5DhQf");
const tempFolder = DriveApp.getFolderById("1u3vbM1hxqKThVMsnjLeLWqLn3CWdTMDO");
const templateDoc = DriveApp.getFileById("1qBtaAfcsHmxU9Y4wp6uQRdFkR95XhVNqpr6tDQ2xH7Q");
const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
body.replaceText("{dt}", info['PO Date'][0]);
body.replaceText("{dpt}", info['Department'][0]);
body.replaceText("{rname}", info['Requestor Name'][0]);
body.replaceText("{item}", info['Item 1'][0]);
body.replaceText("{qty}", info['Qty1'][0]);
body.replaceText("{price}", info['Unit price1'][0]);
openDoc.saveAndClose();
const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Requestor Name'][0] + " " + info['Department'][0]);
tempFolder.removeFile(newTempFile);
return pdfFile;
}
【问题讨论】:
-
请同时贴出调用函数
afterformsubmit的代码。我猜你传递了错误的event object或者属性namedValues确实不存在,就像错误显示的那样。
标签: google-apps-script google-sheets triggers google-forms