用于发送电子邮件的 Google App Script IF 语句

发布于 2025-01-10 12:18:42 字数 1075 浏览 0 评论 0原文

只是想就我在 Google App Script 中的编码寻求一些帮助。

目标:一旦满足第 3 个条件(第 2 个条件位于同一列),我将尝试发送电子邮件。一旦脚本已经向该特定控制号码发送了电子邮件,脚本就不应再次向该交易发送电子邮件。但是,即使脚本已经发送到该事务,它仍然会发送电子邮件。我找不到问题出在哪里或者是否不满足我设定的条件。

列提交状态有“最终、取消、草稿” 列 processBy 有(仅限“ADMIN”)

  if (submissionStatus !== "Draft" && processBy !== "") { // Prevents sending duplicates  
  var subject = "Cash_Advance ";
  MailApp.sendEmail(currentEmail, subjectline, messageBody);
  sheet.getRange(startRow + i, 38).setValue(EMAIL_SENT +" "+ Date()); // column AL
  // Make sure the cell is updated right away in case the script is interrupted
  SpreadsheetApp.flush();
  } //close if statement

  if (submissionStatus !== "Cancelled" && processBy !== "") { // Prevents sending duplicates  
  var subject = "Cash_Advance ";
  MailApp.sendEmail(currentEmail, subjectline, messageBody);
  sheet.getRange(startRow + i, 38).setValue(EMAIL_SENT +" "+ Date()); // column AL
  // Make sure the cell is updated right away in case the script is interrupted
  SpreadsheetApp.flush();
  } //close if statement

Just want to ask some help regarding with my coding in Google App Script.

Objective: Am trying to send emails once I satisfy the 3 condition (the 2 condition is in the same column). And once the script already sent an email to that specific control number the script shouldn't send again to that transaction. However it still sending emails even if the script already sent to that transaction. I can't find where the problem is or if am not satisfying the condition I set.

Column SubmissionStatus have "Final, Cancelled, Draft"
Column processBy have ("ADMIN" only)

  if (submissionStatus !== "Draft" && processBy !== "") { // Prevents sending duplicates  
  var subject = "Cash_Advance ";
  MailApp.sendEmail(currentEmail, subjectline, messageBody);
  sheet.getRange(startRow + i, 38).setValue(EMAIL_SENT +" "+ Date()); // column AL
  // Make sure the cell is updated right away in case the script is interrupted
  SpreadsheetApp.flush();
  } //close if statement

  if (submissionStatus !== "Cancelled" && processBy !== "") { // Prevents sending duplicates  
  var subject = "Cash_Advance ";
  MailApp.sendEmail(currentEmail, subjectline, messageBody);
  sheet.getRange(startRow + i, 38).setValue(EMAIL_SENT +" "+ Date()); // column AL
  // Make sure the cell is updated right away in case the script is interrupted
  SpreadsheetApp.flush();
  } //close if statement

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃繁缕 2025-01-17 12:18:42

您可以简单地将这两个 if 语句合并为一个,也许这就是它多次发送电子邮件的原因。

通过使用 submissionStatus === "Final"

在您最新编辑的上下文中:-

列提交状态有“最终、取消、草稿”列
processBy 有(仅限“ADMIN”)

修改:

if (submissionStatus === "Final" && processBy !== "") // Prevents sending duplicates  
{ 
          var subject = "Cash_Advance ";
          MailApp.sendEmail(currentEmail, subjectline, messageBody);
          sheet.getRange(startRow + i, 38).setValue(EMAIL_SENT +" "+ Date()); // column AL
          // Make sure the cell is updated right away in case the script is interrupted
          SpreadsheetApp.flush();
 } //close if statement

You can simply merge those two if statement into one, maybe that's why it is sending email more than once.

By using submissionStatus === "Final"

In context of your latest edit:-

Column SubmissionStatus have "Final, Cancelled, Draft" Column
processBy have ("ADMIN" only)

Modification:

if (submissionStatus === "Final" && processBy !== "") // Prevents sending duplicates  
{ 
          var subject = "Cash_Advance ";
          MailApp.sendEmail(currentEmail, subjectline, messageBody);
          sheet.getRange(startRow + i, 38).setValue(EMAIL_SENT +" "+ Date()); // column AL
          // Make sure the cell is updated right away in case the script is interrupted
          SpreadsheetApp.flush();
 } //close if statement
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文