我的脚本正在向一列中的给定收件人发送消息,即使已经发送过。目的是在活动工作表上进行搜索,并检查活动行的两列是否符合if
条件。如果是这样,请执行MailApp.sendEmail()
行。
但是,即使该行不符合条件,它也会发送另一封电子邮件。
我认为这是由于我放置for
循环和if
的方式,或者是我的代码中缺少了一些东西。
目标:如果两列的活动行符合条件>发送电子邮件。
其他>忽略/跳过行。
function sendOnEdit(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Dump");
var startRow = 1; // Bypass firts Row that contain Column Titles
var dataRange = sheet.getDataRange();
var data = dataRange.getValues();
for (var rownum = startRow; rownum < data.length; rownum++) { //loop to search for reso == x && emailSent != y
var casenum = data[rownum][5]; // Active Row for Case# Column
Logger.log("Captured Case#: " + casenum);
var emailAddress = data[rownum][1]; // grabs the email address / Email Address Col
Logger.log("Captured Email: " + emailAddress );
var reso = data[rownum][12]; // check cell value / on Spreadsheet reso column is on Data Validation that's either "Yes" or empty.
Logger.log("Captured Y/N: " + reso);
var emailSent =data[rownum][17]; // Current active cell for col "DONE"
Logger.log("Captured DONE?: " + emailSent);
var x = "Yes";
var y = "DONE";
if ( reso == x && emailSent != y ) { // if this is true it should send email with details below if not it will do nothing.
var body = "Hello!";
body += '<p></p>';
//Add to body ...
var subject = "Message Subject" + casenum;
MailApp.sendEmail(emailAddress, subject, body,
{name: 'Automatic Teamline Email', htmlBody: body});
sheet.getRange(rownum + 1, 19).setValue("DONE"); // This will set value of current cell to "DONE"
}
}
}