简体   繁体   English

我正在尝试根据某个类别(mgr,str,wtr)所属的类别发送电子邮件,但它仅发送到该组中的第一封电子邮件?

[英]I am trying to send an email based on which category something falls into (mgr, str, wtr), but it only sends to the first email in the group?

I have been slaving over this piece of code and the script is saying that it's working, the Logger.log, is popping up after every line, but it's only using on of the emails to send the emails to regardless of category. 我一直在忙于这段代码,脚本说它正在运行,Logger.log在每一行之后都会弹出,但是它仅使用其中一个电子邮件将电子邮件发送到任何类别。 I have tried many different solutions, but I think I need some help (I've searched online forEVER and still can't find anything to help for this problem). 我尝试了许多不同的解决方案,但我认为我需要一些帮助(我一直在网上搜索,但仍然找不到任何可解决此问题的方法)。 Here's my code: 这是我的代码:

function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getActiveSheet();
  var sheetProgressReport = ss.getSheetByName("ProgressReport");
  var sheetManagers = ss.getSheetByName("Managers");
  var range = sheetProgressReport.getRange(4, 7, sh.getLastRow(), 1);
  var rangeSentEmail = sheetProgressReport.getRange(4, 8, sh.getLastRow(), 1);
  var column = range.getColumnIndex();
      if(column === 7) {
  var managerEmail = sheetManagers.getRange(22, 2).getValue().toString(); //object to string with respective manager's email
  var strategistEmail = sheetManagers.getRange(23, 2).getValue().toString(); //object to string with respective strategist's email
  var writerEmail = sheetManagers.getRange(24, 2).getValue().toString(); //object to string with respective writer's email
  var client = sheetManagers.getRange(2, 2).getValue().toString(); //object to string with client name
        var message = "Please tell Jordan if you get this! Thank you! :)"; //string with message
  var category = range.getValues();
  var columnSentEmail = rangeSentEmail.getValues();
        var mgr = "mgr";
        var str = "str";
        var wtr = "wtr";
        var EMAIL_SENT = "EMAIL_SENT";
         if (columnSentEmail != EMAIL_SENT && category === "") {email = "";}
                        else if (category = mgr) {email = managerEmail;}
                        else if (category = str) {email = strategistEmail;}
                        else if (category = wtr) {email = writerEmail;}
  MailApp.sendEmail(email, client, message);
   rangeSentEmail.setValue(EMAIL_SENT);
    SpreadsheetApp.flush();
  }
   }

I'm guessing it's something to do with the way that I'm processing (or the lack of processing) the data in the "rangeSentEmail/range" vars. 我猜想这与我在“ rangeSentEmail / range”变量中处理(或缺乏处理)数据的方式有关。 Here's my goal if you can't tell from the messy code: I want to read the top 5-10 lines in the "rangeSentEmail/range" vars, then check to make sure that "rangeEmailSent" is not marked with "EMAIL_SENT"; 如果您不能从凌乱的代码中分辨出来,这就是我的目标:我想阅读“ rangeSentEmail / range”变量中的前5-10行,然后检查以确保“ rangeEmailSent”未标记为“ EMAIL_SENT”; if it meets that requirement, then I want the "range" column to check for labels (mgr, wtr, str) and then send emails to the respective "managerEmail, writerEmail, or strategistEmail" based on which label is in the column. 如果满足该要求,那么我希望“范围”列检查标签(mgr,wtr,str),然后根据该列中的标签将电子邮件发送到相应的“ managerEmail,writerEmail或strategistEmail”。 I honestly can't deduce where the problem is, so PLEASE and THHHAAANNKK YOUUUU in advance! 老实说,我无法推断出问题出在哪里,所以请提前和THHHAAANNKK YOUUUU! I'll be checking up regularly for any help! 我会定期检查是否有任何帮助!

Your problem is here var category = range.getValues() 您的问题在这里var category = range.getValues()

change from getValues() to getValue(). 从getValues()更改为getValue()。 The first is returing an array of objects and the second return only the value, be sure that is a single value. 第一种是重新设置对象数组,第二种仅返回值,请确保该值是单个值。

The second problem is here: 第二个问题在这里:

 if (columnSentEmail != EMAIL_SENT && category === "") {email = "";}
                    else if (category = mgr) {email = managerEmail;}
                    else if (category = str) {email = strategistEmail;}
                    else if (category = wtr) {email = writerEmail;}

Try using only "==" to compare values. 尝试仅使用“ ==”来比较值。 The operator "===" forces you to check if the value AND type are identical and using only one equals "=" just attribute the value to the category variable. 运算符“ ===”强制您检查值和类型是否相同,并且仅使用一个等于“ =”的值,将值归给category变量。 So, use only "==" to make this comparisons. 因此,仅使用“ ==”进行比较。

Best, 最好,

暂无
暂无

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

相关问题 我正在尝试设置一个自动发送电子邮件的 Adwords 脚本,但是当 email 包含“-”时失败 - I am trying to set up an Adwords Script which automatically sends emails but this fails when email contains “-” 尝试创建首先发送电子邮件通知,然后选择随机链接的脚本 - Trying to create script that first sends an email notification, and then selects random link 我正在尝试通过angular发送电子邮件。 我是否以正确的方式处理此问题? - I am trying to send an email via angular. Am I approaching this in the correct manner? 我正在尝试使用process.env和smtp gmail在meteor中发送电子邮件 - I am trying to send a email in meteor with process.env and smtp gmail 我正在尝试在 email 中将谷歌表格中的范围作为 pdf 发送。 我的脚本卡在 getid() - I am trying to send a range in google sheets as a pdf in an email. My script is getting stuck on getid() STMP.js 没有发送电子邮件是我做错了什么吗? - STMP.js is not sending an email is there something I am doing wrong? 我正在尝试通过 nodemailer 发送电子邮件,我已经允许我的谷歌帐户使用不太安全的应用程序,但仍然出现错误 - i am trying to send email through nodemailer, i have permitted my google account for less secure apps, still getiing error 尝试使用sendgrid发送电子邮件时出错 - I am getting an error when attempting to use sendgrid to send email 在 React 登录组件中,Firebase 登录注册正在运行,但是当我尝试发送重置密码链接时,则未发送到电子邮件 - In React Login component Firebase Login signup is working but when I am trying to send a reset password Link then is Not sending to email 使用基于服务器的服务发送电子邮件,该服务可以通过SMTP发送电子邮件 - Send an email with server based service which can dispatch an email via SMTP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM