我希望我的Google脚本只在更改一列时发送电子邮件

时间:2018-05-25 12:27:00

标签: javascript google-apps-script google-sheets comparison logical-operators

现在,我的脚本在状态发生变化时成功发送了电子邮件,但我遇到的问题是,每当进行15(在活动行中)的列发生更改时,它也会发送电子邮件。我希望它只在第15列更改时发送电子邮件,而不是其他任何内容。

我的触发器是From Spreadsheet,On edit

function sendComplete(e) {
  var ss = e.source;
  var s = ss.getSheetByName('Action Items');
  var r = e.range;
  var actionCol = 15;
  var colIndex = r.getColumnIndex();

  if (e.value == "Complete" || "In Progress" || "On Hold" || "Awaiting Parts" || "Need Additional Support" && colIndex == actionCol) {
    var row = r.getRowIndex();
    var userEmail = s.getRange(row, 20).getValue();

    var subject = "Status Change for Event #" + s.getRange(row, 1).getValue();

    var body = "Event: " + s.getRange(row, 1).getValue ();
    body +="\n\nCategory:" + s.getRange(row, 4).getValue ();
    body +="\n\nAsset:" + s.getRange(row, 5).getValue ();
    body +="\n\nSub-Section: " + s.getRange(row, 6).getValue ();
    body +="\n\nComponent: " + s.getRange(row, 6).getValue ();
    body +="\n\nProblem: "+ s.getRange(row, 8).getValue ();
    body +="\n\nAction Update: " + s.getRange(row, 9).getValue ();
    body +="\n\nStatus: " + s.getRange(row, 15).getValue ();

    MailApp.sendEmail(userEmail, subject, body);
  }
}

0 个答案:

没有答案