0
我將兩個基本功能拼湊在一起,以創建一個Google表單,當用戶點擊提交時,該表單返回唯一標識號。這些功能位於電子表格中收集響應並在提交時觸發。今天早上一切都很好。然後在今天下午當提交的表單中的最後一個字段爲「否」時,電子郵件的正文爲空。現在電子郵件的正文總是空白。此代碼是否有任何原因不再有效?谷歌應用程序腳本:mailapp已停止在主體中包含文本
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();
}
}
}
從我所瞭解的你正在閱讀最後一排下面的9排......他們確實是空的......我錯了還是錯過了明顯的東西? (這只是一個建議...) –
感謝您的採訪。它應該在數據的最後一行讀取9列。電子郵件地址和主題最終在電子郵件中,但有時電子郵件的主體是空白的。 – user3285805
?當寫sheet.getRange(startRow,1,numRows,9)時,你正在讀取9行9列,從lastRow列開始A –