Google Sheet在满足单元条件时从列表发送电子邮件

时间:2017-03-02 09:32:03

标签: email google-apps-script google-sheets spreadsheet

我对脚本编程仍然很陌生,无法解决为什么以下脚本不起作用

function sendReturnEmail(event) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var row = sheet.getActiveRange().getRow();
  var cellvalue = ss.getActiveCell().getValue().toString();
  if(event.range.getA1Notation().indexOf("K") && sheet.getRange("K" + row).getDisplayValue() == "Approved")
  {
  var rowVals = getActiveRowValues(sheet);
  var aliases = GmailApp.getAliases();
  var to = rowVals.user;
  var subject = "Allocation request approved";
  var body = "Your allocation request of " +rowVals.quantity + " cases on " + rowVals.date + " from " + rowVals.depot + " has been approved. <br \> <br \>"
    + "Regards, <br \> <br \>" +rowVals.analyst + "<br \> CPF Team";  
Logger.log(aliases);
  GmailApp.sendEmail(to,subject,body,    
                     {from: aliases[0]})
    ;
  }}

  function getActiveRowValues(sheet){
  var cellRow = sheet.getActiveRange().getRow();
  // get depot value
  var depotCell = sheet.getRange("E" + cellRow);
  var depot = depotCell.getDisplayValue();
  // get date value
  var dateCell = sheet.getRange("F" + cellRow);
  var date = dateCell.getDisplayValue();
  // get quantity value
  var quantCell = sheet.getRange("G" + cellRow);
  var quant = quantCell.getDisplayValue();
  // return an object with your values
  var analystCell = sheet.getRange("J" + cellRow);
  var analyst = analystCell.getDisplayValue();
  var userCell = sheet.getRange("O" + cellRow);
  var user = userCell.getDisplayValue();
  return {
    depot: depot,
    date: date,
    quantity: quant,
    analyst: analyst,
    user: user
  } }
}

工作表是问题,其中有几个脚本运行,其中一个是:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "Allocation Requests" ) { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    if( r.getColumn() == 2) { //checks the column
      var nextCell = r.offset(0, 13);
          nextCell.setValue(Session.getEffectiveUser());
      }
  }

我现在希望当K列中的相应单元格手动更改为“已批准”时,工作表会向使用上述脚本捕获的电子邮件地址发送电子邮件(工作正常)。

任何人都可以看到我做错了什么。它运行时没有错误,但我没有收到电子邮件。我搜索了其他问题,但没有人帮忙。非常感谢提前。

0 个答案:

没有答案