Google表格:Mailto脚本问题

时间:2018-07-26 21:39:34

标签: google-apps-script google-sheets

在我的一生中,我无法弄清楚为什么此脚本未发送我的电子邮件。我几乎肯定该脚本是正确的,并且我在Google表格上的设置存在问题。但是想知道是否有人可以看到任何问题或帮助我找出为什么该脚本无法运行。

function sendMail(e) {
  
  var cellvalue = e.value;
  var ss = e.source;
  var sheet = ss.getActiveSheet();
  var cell = sheet.getActiveCell().getA1Notation();
  var sheetName = sheet.getName();
  var PRSR = sheet.getRange("B"+e.range.getRow()).getValue();
  
  var aValue = sheet.getRange("A"+e.range.getRow()).getValue();
  var cValue = sheet.getRange("C"+e.range.getRow()).getValue();
  var dValue = sheet.getRange("D"+e.range.getRow()).getValue();
  
  switch(PRSR){
    case "SP":
      recipients = "admin@myutahmortgage.com";
      break;
    case "TD":
      recipients = "admin@myutahmortgage.com";
      break;
    case "BM":
      recipients = "admin@myutahmortgage.com";
      break;
    default:
      recipients = "admin@myutahmortgage.com";
      break;
  }

  var message = '';
  if(cellvalue.toUpperCase() === 'NO' && parseInt(e.range.getColumn()) == 6){ 
    
    message = 'Cell ' + cell + ' in Sheet ' + sheetName + ' was changed to NO.';
    message = message + " "+ aValue + " " + cValue + " "+dValue;
    
    var subject = 'Cell Changed to NO in Inspection Checklist';
    var body = message + '  Visit ' + ss.getUrl() + ' to view the changes';
    MailApp.sendEmail(recipients, subject, body);
  }
}

1 个答案:

答案 0 :(得分:0)

该脚本对我来说很好用。我在以下电子表格中进行了设置:https://docs.google.com/spreadsheets/d/1fKGBOyvWG0qkN5ldCM4WbMuP9gp31NCXjQLQvVaaNTE/edit?usp=sharing

我转到菜单项“当前项目的触发器”并设置了要运行的触发器

  • sendMail |从电子表格|编辑时

Google Apps Script Current project's trigger set sendMail function, From spreadsheet, On edit

我向电子表格中添加了满足A:F要求的脚本语句的数据

enter image description here

当我将OK更改为NO时,它满足下面脚本行中的'if'测试,因此发送电子邮件。

if(cellvalue.toUpperCase()==='否'&& parseInt(e.range.getColumn())== 6){