如果" Null"请不要发送电子邮件。细胞中的价值

时间:2016-04-08 17:25:34

标签: javascript google-sheets

如果emailSentCol!== Email_Sent,我的脚本目前设置为不发送电子邮件。如果emailSentCol中的单元格为空,我也希望它不发送。有什么建议?谢谢你们。第12行

function myFunction() {
  var EMAIL_SENT = "EMAIL_SENT";

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Administrators");
  if (sheet != null) {
    var data = sheet.getDataRange().getValues();
    var startRow = 1; //The starting row of data (zero indexed)
    var emailCol = 1; //The column that the email address is in (zero indexed)
    var messageCol = 28; //The column that the message is in (zero indexed)
    var emailSentCol = 29; //The column that the EMAIL_SENT note is in (zero indexed)
    for (var i = startRow; i < data.length; i++) {
      if (data[i][emailSentCol] !== EMAIL_SENT) {
        var emailAddress = data[i][emailCol];
        var subject = "Tuition Reimbursement Status";
        var message = data[i][messageCol];
        if(emailAddress !== null && emailAddress !== '' && emailAddress !== "") {
          MailApp.sendEmail(emailAddress, subject, message);
          sheet.getRange(i+1,emailSentCol+1).setValue(EMAIL_SENT);
        }
      }
    }
  }

1 个答案:

答案 0 :(得分:0)

修改你的if结构如下:

if (data[i][emailSentCol] && data[i][emailSentCol] !== EMAIL_SENT) {

这确保在检查之前必须定义data [i] [emailSentCol]并且非null,以查看它是否未被发送。