截至上周,Google文档邮件合并脚本无效

时间:2015-05-25 13:10:52

标签: javascript google-apps-script google-sheets google-docs

我们用于5个谷歌文档的邮件合并脚本上周停止了工作 - 几周前类似的事情发生在DocsList过时并且我能够解决它,但现在它已经停止工作了。

var docTemplate = "15kvC3M8b0Me3Vi3GwErQvG60BlTC0qAHMXrlc3Ocky8";  
var docName     = "RefundByCheck"

function onFormSubmit(e) { 
   var first_name = e.values[1];
   var last_name = e.values[2];
   var customer_email = e.values[3];
   var brand = e.values[4];
   var amount = e.values[5];
   var purchase_date = e.values[6];
   var customer_address = e.values[7];
   var rep_name = e.values[8];
   var order_number = e.values[9];
   var copyId = DriveApp.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('keyPurchaseDate', purchase_date);
   copyBody.replaceText('keyAddress', customer_address);
   copyBody.replaceText('keyRep', rep_name);
   copyBody.replaceText('keyOrder', order_number);
   var todaysDate = Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy"); 
   copyBody.replaceText('keyTodaysDate', todaysDate);
   copyDoc.saveAndClose();
   var pdf = DriveApp.getFileById(copyId);
   var theblob = pdf.getBlob().getAs('application/pdf');
   var folder = DriveApp.getFolderById('0B3nrCN8N5OBcRnlWaUlHZUxZNE0');
   var movefile = folder.createFile(theblob);
   DriveApp.removeFile(movefile);
   var subject = "Text goes here" + order_number
   var body    = "Hello " + first_name + " " + last_name + "," + "<br /><br />" 
   + "Text goes here" + "<br /><br />"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   var cc = "test@test.com";
   MailApp.sendEmail(customer_email, subject, body, {htmlBody: body, attachments: pdf, cc: cc}); 
   DriveApp.getFileById(copyId).setTrashed(true);
}

我有一种感觉,谷歌更新了其他内容,我需要更改我的代码,但我不确定 - 由于我收到的失败通知摘要,我很确定这部分内容已被破坏:5/25/15 8:59 AM onFormSubmit我们很抱歉,目前没有服务器可用。请稍等一下再试一次。(第41行,文件&#34; RefundByCheckCode&#34;)

   var movefile = folder.createFile(theblob);

有任何想法或建议吗?

1 个答案:

答案 0 :(得分:1)

这似乎是Issue 3206,&#34;发送带有附件附件的邮件(作为PDF)始终失败&#34;。访问该缺陷并将其标记为更新。您的脚本中似乎没有新的方案,但如果您有任何其他信息可能有助于负责解决此问题的Google员工,则可以向问题跟踪器添加评论。

由于问题似乎是在脚本成功运行后的某个时间出现的,然后是持久的,我建议复制脚本,然后停用原始脚本。

编辑:OP能够通过部署替换他们的模板文件来解决问题。