简体   繁体   English

我不知道为什么这个脚本忽略了向某些收件人发送电子邮件

[英]I don't know why this script ommits sending emails to some of the recipients

I want to run this script on 2 separate target numbers on a certain sheet within the spreadsheet.我想在电子表格中某个工作表上的 2 个单独的目标编号上运行此脚本。 The idea is to check individual job budgets and send out an email if it is too low then mark column C with EMAIL sent so I know it was successful.这个想法是检查个人工作预算并发送 email 如果它太低然后用 EMAIL 标记列 C 发送所以我知道它是成功的。 I only seems to be sending email to the first out of 4 address on the first checksales but sending to all 4 emails on the 2nd checksales.我似乎只在第一次支票销售时将 email 发送到 4 个地址中的第一个,但在第二次支票销售时发送到所有 4 封电子邮件。

  var monthSalesRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("PROJECT PIPELINE").getRange("I4"); 
  var monthSales = monthSalesRange.getValue();
  var ui = SpreadsheetApp.getUi(); 
  // Check totals sales
  if (monthSales < 7000){
    ui.alert('Epic SG Budget Running Low!');
var EMAIL_SENT = 'EMAIL_SENT';
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Emails");
  var startRow = 2; // First row of data to process
  var numRows = 4; // Number of rows to process
  var dataRange = sheet.getRange(2,1,4,3);
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var emailAddress = row[0]; // First column
    var message = row[1]; // Second column
    var emailSent = row[2]; // Third column
    if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
      var subject = 'Low Labor Budget Alert';
      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 3).setValue("EMAIL_SENT");
      // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush()
  var monthSalesRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("PROJECT PIPELINE").getRange("I10"); 
  var monthSales = monthSalesRange.getValue();
  var ui = SpreadsheetApp.getUi(); 
  // Check totals sales
  if (monthSales < 8000){
    ui.alert('Seward Budget Running Low!');
var EMAIL_SENT = 'EMAIL_SENT';
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Emails");
  var startRow = 10; // First row of data to process
  var numRows = 4; // Number of rows to process
  // Fetch the range of cells A10:B11
  var dataRange = sheet.getRange(10,1,4,3);
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var emailAddress = row[0]; // First column
    var message = row[1]; // Second column
    var emailSent = row[2]; // Third column
    if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
      var subject = 'Low Labor Budget Alert';
      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 3).setValue("EMAIL_SENT");
      // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush()
    }
  }
}
    }
  }
  }
}


You haven't closed off your first for loop and if statement.你还没有关闭你的第一个 for 循环和 if 语句。

You need to add }} after your first SpreadsheetApp.flush() ie您需要在第一个 SpreadsheetApp.flush() 之后添加 }} 即

  SpreadsheetApp.flush() } }

And you'll have to remove a couple of braces from the end of the script to get it to run.而且您必须从脚本末尾删除几个大括号才能使其运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM