【发布时间】:2019-05-09 00:48:43
【问题描述】:
我有一个现场工作人员填写并提交的 Google 表单。附加的 javascript 将表单的内容作为电子邮件发送给办公室中的每个人。
执行时间超长。一个报告了 19496 秒,此时 Gsuite 应在 5 分钟自动终止任何脚本。有些在 Google 应用脚本执行日志中具有“未知”状态和 0 秒。
Gsuite 配额是否已用完?我的脚本有错误吗?
运行脚本触发器的用户也会收到一封退回电子邮件,即使所有电子邮件都在通过,并且 Google 工作表正在正常接收来自 Google 表单的响应。
我尝试在顶部添加“if(e.values && !e.values[1]){return;}”和“return;”在底部。它似乎没有改变这个问题。
我编辑了下面的 google 应用脚本以删除电子邮件地址的真实列表,并缩短了报告。 Google 表单的目的是提供他们日常工作的真实摘要,而不仅仅是在电子邮件中“工作完成”。因此,他们改为填写 15 个问题的列表。
function myFunction(e){
// Set values for event "e" from Response form, each number being a column in the spreadsheet
var value1 = e.values[1];
var value2 = e.values[2];
var value3 = e.values[3];
var value4 = e.values[4];
var value5 = e.values[5];
// Build subject and message for email that will be sent out
var subject1 = value5 + " Job #" + value2 + " " + value3 + " Job Report Submitted " + value1 + " -oOo-";
var message_html = "<b>Date:</b> " + value1 + "<br>" +
"<b>Job Number:</b> " + value2 + "<br>" +
"<b>Site Name:</b> " + value3 + "<br>" +
"<b>Client:</b> " + value4 + "<br>" +
"<b>Crew Chief:</b> " + value5 + "<br>";
// Send email to chief, of what the chief submitted through the Response form
var chiefemail = "leo@email.com"; //setting leo email as the default - but this should not be used based on below
var chiefname = "Leo E.";
if (value5 == "Bryan N.") {
chiefemail = "bryan@email.com";
chiefname = "Brian N";}
else if (value5 == "Carl B.") {
chiefemail = "carl@email.com";
chiefname = "Carl B";
}
else if (value5 == "Clay W.") {
chiefemail = "clay@email.com";
chiefname = "Clay W";
}
else if (value5 == "Dakota P."){
chiefemail = "dakota@email.com";
chiefname = "Dakota P";
}
// Send emails to all office staff:
var EmailList = "brian@email.com," + chiefemail;
MailApp.sendEmail({
to: EmailList,
subject: subject1,
htmlBody: message_html,
name: chiefname,
replyTo: chiefemail
});
}
我希望脚本终止,并且我不想收到退回的电子邮件。救命!
【问题讨论】:
-
执行时间限制取决于账户类型。见developers.google.com/apps-script/guides/services/quotas
标签: google-apps-script google-sheets triggers google-forms