我拼凑了两个基本功能来创建一个Google表单,在用户点击提交时返回一个唯一的识别号码。这些功能位于电子表格中,其中收集响应并在提交时触发。今天早上一切都很好。然后今天下午,当提交表单中的最后一个字段为“否”时,电子邮件的正文是空白的。现在,电子邮件的正文始终是空白的。这段代码有什么原因不再有效吗?
function addFormula() {
var sheet1 = SpreadsheetApp.getActiveSheet();
var startRow1 = 2;
var startColumn1 = 6;
var numberRows1 = 1;
var numberColumns1 = 9;
var lastRow1 = sheet1.getLastRow();
var sourceRange1 = sheet1.getRange(startRow1, startColumn1, numberRows1, numberColumns1);
var destinationRange1 = sheet1.getRange(lastRow1, startColumn1, numberRows1, numberColumns1);
sourceRange1.copyTo(destinationRange1);
};
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = sheet.getLastRow(); // First row of data to process
var numRows = 9; // Number of rows to process
// Fetch the range of cells
var dataRange = sheet.getRange(startRow, 1, numRows, 9)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var TimeStamp = row[0]; // First column
var Name = row[1]; // Second column
var Email = row[2]; // Third column
var Leg1 = row[3];
var CNeed = row[4];
var Year = row[5];
var CCode = row [6];
var Number = row [7];
var TripNumber = row [8];
var emailSent = row [9];
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = "Automated Message: Your Trip Number";
MailApp.sendEmail(Email, subject, TripNumber);
sheet.getRange(startRow + i, 10).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
答案 0 :(得分:0)
我想我明白了。这两个函数都在表单提交时执行,而且它是随机的,首先会触发。我将这两个函数合并为一个,看起来它解决了这个问题。谢谢Serge帮忙。