从第N列获取最后一行单元格的值,如果匹配特定单词,则发送电子邮件

时间:2019-06-05 05:51:55

标签: google-apps-script google-sheets

我无法获取此脚本来检查整列并获取要比较的最后一行单元格值。仅当我输入匹配的单个单元格时,它才起作用。

尝试了此脚本,并尝试了我在stackoverflow上发现的许多变体,但对我没有用。

function CNIC(){
  CheckCnic();
}

function CheckCnic() {
  // Fetch the Assigned Team
  var getassignedto = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Man Ticketing Log"); 
  var range = getassignedto.getRange('N:N');
  var lastRow = getassignedto.getLastRow();
  var values = range.getValues();
  var department = range.getValue();
  //var department = lastRow.getValue(); // This is the return value 
    of CNIC to match

  // Check if matches CNIC
  if (department == "CNIC"){
    // Fetch the email address
    var emailAddress = ("myemail@mydomain.com");

    // Send Alert Email.
    var message = 'ATTENTION ' + department; // Second column
    var subject = 'A NEW TICKET HAS BEEN ADDED';
    MailApp.sendEmail(emailAddress, subject, message);
  }
}

1 个答案:

答案 0 :(得分:0)

它只有一个单元格,因为这正是您要它执行的操作。

var values = range.getValues(); var department = range.getValue();

getValue()返回单个单元格的值。如果要检查一列中的多行,请遍历values或使用TextFinder