Google Apps 脚本中的电子邮件地址选择器

Email address selector in Google Apps script

我有一个脚本 select 电子邮件地址,具体取决于下拉菜单的结果 select 或按预期工作的表单。

但是我有另一个下拉列表,如果“08-Maintenance”是 selected,我希望它覆盖电子邮件 selector。这一点不起作用。非常感谢任何帮助。

//select THIS spreadsheet
var LogSheet = SpreadsheetApp.getActiveSpreadsheet(); 

//select correct worksheet  
var sheet = LogSheet.getSheetByName("LOG"); 

//declare the row to look at (the last row)
var lastRowNumber = sheet.getDataRange().getNumRows();

//declare and obtain the variable for the Source Code in column 3  
var SourceValue = sheet.getRange(lastRowNumber, 3).getValue(); 

//declare and obtain the variable for the Location Code in column 4 
var LocationValue = sheet.getRange(lastRowNumber,4).getValue();

//declare and obtain the variable for the Hazard being reported in column 6 
var HazardValue = sheet.getRange(lastRowNumber,6).getValue();

//declare the correct email addresses to use
  var email01 = LogSheet.getSheetByName("LocationCodes").getRange(3, 5).getValue();
  var email02 = LogSheet.getSheetByName("LocationCodes").getRange(4, 5).getValue();
  var email03 = LogSheet.getSheetByName("LocationCodes").getRange(5, 5).getValue();
  var email04 = LogSheet.getSheetByName("LocationCodes").getRange(6, 5).getValue();
  var email05 = LogSheet.getSheetByName("LocationCodes").getRange(7, 5).getValue();
  var email06 = LogSheet.getSheetByName("LocationCodes").getRange(8, 5).getValue();
  var email07 = LogSheet.getSheetByName("LocationCodes").getRange(9, 5).getValue();
  var email08 = LogSheet.getSheetByName("LocationCodes").getRange(10, 5).getValue();
  var email09 = LogSheet.getSheetByName("LocationCodes").getRange(11, 5).getValue();
  var email10 = LogSheet.getSheetByName("LocationCodes").getRange(12, 5).getValue();
  var email11 = LogSheet.getSheetByName("LocationCodes").getRange(13, 5).getValue();
  var email12 = LogSheet.getSheetByName("LocationCodes").getRange(14, 5).getValue();
  var email13 = LogSheet.getSheetByName("LocationCodes").getRange(15, 5).getValue();
  var email14 = LogSheet.getSheetByName("LocationCodes").getRange(16, 5).getValue();
  var email15 = LogSheet.getSheetByName("LocationCodes").getRange(17, 5).getValue();
  var email16 = LogSheet.getSheetByName("LocationCodes").getRange(18, 5).getValue();
  var email17 = LogSheet.getSheetByName("LocationCodes").getRange(19, 5).getValue();
  var email18 = LogSheet.getSheetByName("LocationCodes").getRange(20, 5).getValue();
  var email19 = LogSheet.getSheetByName("LocationCodes").getRange(21, 5).getValue();  
  var email20 = LogSheet.getSheetByName("LocationCodes").getRange(22, 5).getValue(); 

//declare the correct LocationCodes to check
  var depot01 = LogSheet.getSheetByName("LocationCodes").getRange(3, 4).getValue();
  var depot02 = LogSheet.getSheetByName("LocationCodes").getRange(4, 4).getValue();
  var depot03 = LogSheet.getSheetByName("LocationCodes").getRange(5, 4).getValue();
  var depot04 = LogSheet.getSheetByName("LocationCodes").getRange(6, 4).getValue();
  var depot05 = LogSheet.getSheetByName("LocationCodes").getRange(7, 4).getValue();
  var depot06 = LogSheet.getSheetByName("LocationCodes").getRange(8, 4).getValue();
  var depot07 = LogSheet.getSheetByName("LocationCodes").getRange(9, 4).getValue();
  var depot08 = LogSheet.getSheetByName("LocationCodes").getRange(10, 4).getValue();
  var depot09 = LogSheet.getSheetByName("LocationCodes").getRange(11, 4).getValue();
  var depot10 = LogSheet.getSheetByName("LocationCodes").getRange(12, 4).getValue();
  var depot11 = LogSheet.getSheetByName("LocationCodes").getRange(13, 4).getValue();
  var depot12 = LogSheet.getSheetByName("LocationCodes").getRange(14, 4).getValue();
  var depot13 = LogSheet.getSheetByName("LocationCodes").getRange(15, 4).getValue();
  var depot14 = LogSheet.getSheetByName("LocationCodes").getRange(16, 4).getValue();
  var depot15 = LogSheet.getSheetByName("LocationCodes").getRange(17, 4).getValue();
  var depot16 = LogSheet.getSheetByName("LocationCodes").getRange(18, 4).getValue();
  var depot17 = LogSheet.getSheetByName("LocationCodes").getRange(19, 4).getValue();
  var depot18 = LogSheet.getSheetByName("LocationCodes").getRange(20, 4).getValue();
  var depot19 = LogSheet.getSheetByName("LocationCodes").getRange(21, 4).getValue();
  var depot20 = LogSheet.getSheetByName("LocationCodes").getRange(22, 4).getValue();


//send the email to the 'recipient' 
//if SourceValue is recorded as 08 - Mantenance Request System, the recipient is engineering.support@websiteaddress
//otherwise check location code and send to corresponding H&S Co-ordinator's email address

if (SourceValue == "08 - Mantenance Request System") {
    var recipient = "engineering.support@websiteaddress";

//Start with first depot in list

    } else if (LocationValue == depot01) {
    var recipient = email01;

    } else if (LocationValue == depot02) {
    var recipient = email02;

    } else if (LocationValue == depot03) {
    var recipient = email03;

    } else if (LocationValue == depot04) {
    var recipient = email04;

    } else if (LocationValue == depot05) {
    var recipient = email05;

    } else if (LocationValue == depot06) {
    var recipient = email06;

    } else if (LocationValue == depot07) {
    var recipient = email07;

    } else if (LocationValue == depot08) {
    var recipient = email08;

    } else if (LocationValue == depot09) {
    var recipient = email09;

    } else if (LocationValue == depot10) {
    var recipient = email10;

    } else if (LocationValue == depot11) {
    var recipient = email11;

    } else if (LocationValue == depot12) {
    var recipient = email12;

    } else if (LocationValue == depot13) {
    var recipient = email13;

    } else if (LocationValue == depot14) {
    var recipient = email14;

    } else if (LocationValue == depot15) {
    var recipient = email15;

    } else if (LocationValue == depot16) {
    var recipient = email16;

    } else if (LocationValue == depot17) {
    var recipient = email17;

    } else if (LocationValue == depot18) {
    var recipient = email18;

    } else if (LocationValue == depot19) {
    var recipient = email19;

    } else if (LocationValue == depot20) {
    var recipient = email20;

} else {

//and send to Engineering Support if there is no code as a catch all.
    var recipient = "engineering.support@websiteaddress";  //CHANGE TO ENG SUPP
}

//with the 'LocationCode' & 'SourceCode' as the subject
var subject = SourceValue ;  

//then write the'body' of the email including the link to see the changes
var body = 'A new [' + SourceValue + '] log entry has been recorded at [' + LocationValue  + '],  listed as [' + HazardValue + '], please click the link > > http://goo.gl/shortcode < < to view details.';

{ 
//then send the email 
MailApp.sendEmail(recipient,subject,body); 
}

出于显而易见的原因,我已经更改了网站地址和 goo.gl 短代码!

您的比较值似乎拼错了:

应该是Maintenance而不是Mantenance:

if (SourceValue == "08 - Mantenance Request System") {
    var recipient = "engineering.support@websiteaddress";

//Start with first depot in list

    } else if (LocationValue == depot01) {
    var recipient = email01;

我会使用三个等号进行比较:

if (SourceValue === "08 - Maintenance Request System") {

您可以搜索 post 这样的不同之处:

Stack Overflow Link