2016-04-08 69 views
-2

如果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); 
     } 
     } 
    } 
    } 

回答

0

修改你的if結構是如下:

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

這保證了數據的[I] [emailSentCol]必須定義和你的支票非空之前,看它是否是未發送。

+1

感謝ManoDestra它工作完美! –

相關問題