由于 DocsList 的贬值,我的脚本从 Google Drive 中的模板生成 pdf 文档并根据电子表格中的列将其通过电子邮件发送给收件人今天停止工作。请参阅此处:https : //developers.google.com/google-apps/documents-list/
我已尝试按照本指南https://developers.google.com/drive/web/migration进行更新以使用 DriveApp 更新 DocsList 的所有实例,但我无法使其正常工作。有人可以帮我更新这个脚本以使其正常工作吗?我在此脚本中有 6 个“DocsList”实例,我能够正确更新其中一些实例,但其他一些(例如“addFile”)似乎需要不同的格式。即使在尝试简单地查找“DocsList”并将其替换为“DriveApp”后,我仍收到以下错误消息:
“类型错误:在对象 ProofOfCredit_CNZDTVR44N.pdf 中找不到函数 addFile。(第 45 行,文件“ProofOfCreditCode”)”
我将不胜感激任何建议和帮助,因为这种折旧破坏了我的 5 个脚本,这些脚本与这个脚本几乎相同。
var docTemplate = "1JAPmsrPRrRwXCVAli229C5J7Kr4xaOnfO2rmGqvYyhU";
var docName = "ProofOfCredit";
function onFormSubmit(e) {
var first_name = e.values[1];
var last_name = e.values[2];
var customer_email = e.values[3];
var order_number = e.values[4];
var brand = e.values[5];
var amount = e.values[6];
var date_of_credit = e.values[7];
var auth_code = e.values[8];
var last_4 = e.values[9];
var request_id = e.values[10];
var rep_name = e.values[11];
var copyId = DocsList.getFileById(docTemplate)
.makeCopy(docName+'_'+order_number)
.getId();
var copyDoc = DocumentApp.openById(copyId);
var copyBody = copyDoc.getActiveSection();
copyBody.replaceText('keyFirst', first_name);
copyBody.replaceText('keyLast', last_name);
copyBody.replaceText('keyBrand', brand);
copyBody.replaceText('keyAmount', amount);
copyBody.replaceText('keyCreditdate', date_of_credit);
copyBody.replaceText('keyAuth', auth_code);
copyBody.replaceText('keyRep', rep_name);
copyBody.replaceText('keyOrder', order_number);
copyBody.replaceText('keyCClast4', last_4);
copyBody.replaceText('keyRequestID', request_id);
var todaysDate = Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy");
copyBody.replaceText('keyTodaysDate', todaysDate);
copyDoc.saveAndClose();
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
var folder = DocsList.getFolder('Proof of Credit');
var movefile = DocsList.createFile(pdf);
movefile.addToFolder(folder);
movefile.removeFromFolder(DocsList.getRootFolder());
var subject = "Proof of Credit regarding Order Number: " + order_number;
var body = "Hello " + first_name + " " + last_name + "," + "<br /><br />"
+ "Thank you for calling " + brand + " Support. The attached document contains information "
+ "for you to reference related to the credits we have issued back to your original form of payment." + "<br /><br />"
+ "If you have any further questions or require additional assistance please let us know." + "<br /><br />"
+ "Regards," + "<br /><br />"
+ rep_name + ", Payments Department" + "<br />"
+ "test@test.com";
var cc = "test@test.com";
MailApp.sendEmail(customer_email, subject, body, {htmlBody: body, attachments: pdf, cc: cc});
DocsList.getFileById(copyId).setTrashed(true);
}