google-apps-script - Google Apps 脚本 : "We' re sorry, 发生服务器错误。请稍等一下,然后重试”

标签 google-apps-script

我正在使用 Google Apps 脚本来设置电子表格合并到将通过电子邮件发送的发件人信函。我复制了一个类似的脚本并添加了我的信息。 每次我尝试保存它时,都会收到“我们很抱歉发生服务器错误。请稍等一下,然后重试。”

//  <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6c2cfdecfc3e6dfc3cacac9d1c2c9c1cdc8cfd2d2cfc8c188c5c9cb" rel="noreferrer noopener nofollow">[email protected]</a>
//  Job Offer Letter

//  Get template from Google Docs and name it
var docTemplate = "1Y5ohbBWPeLSvNijge6I3ueQpulFzeZTky7853sKGSj8";
var docName = "HR_2_Job_Offer_form_letter";

//  When Form Gets Submitted
function onFormSubmit(e) {

//  Get information from form and set our variables

var email_address = e.values[10];
var date = e.values[1];
var first_name = e.values[2];
var last_name = e.values[3];
var job_title = e.values[11];
var status = e.values[13];
var hourly_wage = e.values[14];
var start_date = e.values[15];

//  Get document template, copy it as a new temp doc, and save the doc's id
var copyId = DocList.getFileById(docTemplate)
        .makeCopy(docName+' for '+first_name last_name)
        .getId();

//  Open the temporary document
var copyDoc = DocumentApp.openById(copyId);

//  Get the document's body section
var copyBody = copyDoc.getActiveSection();

//  Replace place holder keys, in our google doc template
copyBody.replaceText('keyTodaysDate', date);
copyBody.replaceText('keyFirstName', first_name);
copyBody.replaceText('keyLastName', last_name);
copyBody.replaceText('keyJobTitle', job_title);
copyBody.replaceText('keyStatus', status);
copyBody.replaceText('keyHourlyWage', hourly_wage);
copyBody.replaceText('keyStartDate', start_date);

//  Save and close the temporary document
copyDoc.saveAndClose();

//  Convert document to PDF
var pdf = DocList.getFileById(copyId).getAs("application/pdf")'

//  Attach PDF and send the email
var subject = "Job Offer";
var body = "Here is the Job Offer for " + first_name last_name + "";
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf});

//  Delete temp file
DocsList.getFileById(copyId).setTrashed(true);
}

最佳答案

当幕后抛出某种 Javascript 错误时,就会发生这种情况。

为了找出哪一行有错误,请在代码的第一行放置一个断点(通过单击行号左侧来执行此操作。)

然后单步执行代码并查看何时弹出服务器错误。然后我们可以帮助您找出该特定行的问题所在。

关于google-apps-script - Google Apps 脚本 : "We' re sorry, 发生服务器错误。请稍等一下,然后重试”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19553828/

相关文章:

google-apps-script - 创建 Google 电子表格的副本,无需复制脚本

google-apps-script - 从 Google App Script 应用程序调用 Google Drive SDK

javascript - 如何使用 javascript 变量分配 Google Apps 脚本变量?

javascript - 数组不能在数据表中使用

html - 对 bigquery.jobs.query 的 API 调用失败,错误为 : Access Denied: Project ppc-big-query: User does not have bigquery. jobs.create 权限

javascript - 如何修复 Google 脚本中的 'TypeError: Cannot find function insertColumns'

javascript - 在表格脚本中从日期中减去日期时遇到问题

javascript - 将 Gmail 放入 Google 表格中

datetime - GAS 函数返回不正确的日期 - 是我还是缺陷?

javascript - 谷歌应用程序脚本。检查 Range1 是否与 Range2 相交