我正在处理一个电子表格,该表格循环遍历两列中的值。一列(47)包含将在电子邮件中发送的消息,而另一列(48)包含发送消息的时间戳。
脚本检查消息值是否为空以及时间戳是否为空。如果是这样,这意味着消息从未发送过,然后脚本发送消息。
如果时间戳列中有值,我希望它不发送消息。我之前使用过它并且过去曾经使用过,我不知道它为什么现在不能正常工作。即使有时间戳,它仍会发送消息。我错过了什么?这是代码(抱歉,它不是最好的书面代码,我知道。任何提高它的建议都会受到赞赏):
function listingPending2WeekNoticeEmail() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("VacancyReportMarketing");
// figure out what the last row is
var lastRow = sheet.getLastRow();
// the rows are indexed starting at 1, and the first 3 row
// is the headers, so start with row 4
var startRow = 4;
// grab the '2 week notice sent' column 48 (AV))
var range = sheet.getRange(2,48,lastRow-startRow+1,1 );
var numRows = range.getNumRows();
var timestamp_values = range.getValues();
// Now, grab the listing pending 2 week notice column 47 (AU)
range = sheet.getRange(4, 47, lastRow-startRow+1, 1);
numRows = range.getNumRows();
var reminder_info_values = range.getValues();
var warning_count = 0;
var msg = "";
// Loop over the days left values
for (var i = 0; i <= numRows - 1; i++) {
var timestamp = timestamp_values[i][0];
var reminder_info = reminder_info_values[i][0];
// var days_left = days_left_values[i][0];
if(reminder_info != '' && timestamp == '') {
Logger.log(timestamp);
// if reminder not empty but timestamp empty, do something with the data.
var reminder_name = reminder_info_values[i][0];
msg = msg + reminder_name+"\n\n";
var msg2 = "\n"+"Within the 2 weeks prior to unit being estimated ready, Marketing Department should begin advertising the above units. If assets are missing, Marketing should begin scheduling with the property manager a time to visit the property as soon as it is ready. Please begin to compile your schedule to collect missing assets and submit to Marketing Manager for approval. Thank you!"
warning_count++;
}
}
if(warning_count) {
MailApp.sendEmail("example@gmail.com,example@yahoo.com",
"2 WEEK NOTICE - LISTINGS PENDING", msg+msg2);
timestamp2WeekNoticeSent();
}
};
function timestamp2WeekNoticeSent(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("VacancyReportMarketing");
var lastRow = sheet.getLastRow()
for (var i = 1; i <= lastRow; i++){
// get column AU (47), every row to last row
var noticeRange = sheet.getRange([i], 47);
var noticeValues = noticeRange.getValues();
// get column AV (48), every row to last row
var timeRange = sheet.getRange([i], 48);
var timeValues = timeRange.getValues();
if (noticeValues != '' && timeValues == ''){ //
timeRange.setValue(new Date());
}
}
}
答案 0 :(得分:1)
我刚刚意识到,当我的起始行应该为4时,我从第2行开始获取第48列的范围。我正在以第4列开始的范围从4开始,就像我应该的那样。由于不匹配,当我循环遍历值时,它们不会在同一行中循环。所以我只是将第48列的getRange值更改为4而不是2,现在它正在工作。啊...