【发布时间】:2021-09-01 05:46:23
【问题描述】:
我正在尝试创建一个函数,在提交 Google 表单时,它将基于模板文档生成 PDF。但是,当我尝试运行脚本时,仍然出现错误,显示 error in line 2 e.namedvalue(e)。
function afterFormSubmit(e) {
const info = e.namedValues;
createPDF(info);
}
function createPDF(info) {
const pdfFolder = DriveApp.getFolderById("1BSBIOPWFoc7o2nbX8XT23C85_pBq02VE");
const tempfolder = DriveApp.getFolderById("1xSl7VhVwHAmIcVOdXVUlzwZcZ27q3hqU");
const templateDoc = DriveApp.getFileById("1vc7rTRU88LDF07hJs5Waf4OIWy2pAeoFNkB8UBpDnqI");
const newTempFile = templateDoc.makeCopy(tempfolder);
const opendoc = DocumentApp.openById(newTempFile.getId())
const body = opendoc.getBody();
body.replaceText("{dor}", info['Timestamp'][0]);
body.replaceText("{fn}", info['Name ( Nama )'][0]);
body.replaceText("{nric}", info['NRIC/ID/PASSPORT ( No kad pengenalan/pasport )'][0]);
const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Name ( Nama )'][0] + " " + info['Timestamp'][0]);
}
【问题讨论】:
-
你是怎么运行这个函数的,你有没有安装 afterFormSubmit 作为一个可安装的触发器?
-
是的...已经在表单提交后放置了触发器。
标签: javascript pdf google-apps-script google-forms