【问题标题】:Need to send an email to Form respondents based on question answer需要根据问题答案向表单回复者发送电子邮件
【发布时间】:2021-06-30 00:23:05
【问题描述】:

我需要一些帮助!如果他们选择任何 AcLab Session Full 答案,我正在尝试自动向表单受访者发送电子邮件。可能的答案范围从空白到 AcLab Session Full19

我成功地让它在每次回复时发送一封电子邮件,唯一的问题是我需要它仅在受访者选择特定内容时发送,而不是所有内容。

现在我把代码弄乱了,它根本不工作!

这是我认为我搞砸的地方(请记住,我不是开发人员或编码人员,这是从许多不同的地方拼凑而成的,可能不正确)

function AutoConfirmation(e)
{
      var theirFirst = e.values[2];
      var theirEmail = e.values[1];
      var theirSession= e.values[4];
      var subject = "Action Required: Your Selected AcLab Session is Full";
      var message = "Thank you " + theirFirst + ",<br> <br> The AcLab session that you have selected for this week is full. " 
      var cosmetics = {htmlBody: message};
      
 if (SpreadsheetApp.getActive().getSheetByName('Form Responses 1').getRange('Form Responses 1!E2:E10000').getValue(theirSession)=""||"AcLab Session Full1"||"AcLab Session Full2"||"AcLab Session Full3"||"AcLab Session Full4"||"AcLab Session Full5"||"AcLab Session Full6"||"AcLab Session Full7") return;
MailApp.sendEmail (theirEmail, subject, message, cosmetics);}

【问题讨论】:

  • 如果你想要一个比下面提供的更好的答案,那就问一个更好的问题,因为我不清楚你在问什么

标签: javascript if-statement google-apps-script google-sheets google-forms


【解决方案1】:

如果您想在满足条件时发送电子邮件,则需要将该代码放在 IF 中:

if (condition) {
  MailApp.sendEmail(theirEmail, subject, message, cosmetics);
}

在您的情况下,此条件是所选值是否是表单答案 (theirSession) 中指定的会话值之一:

if (theirSession === "AcLab Session Full1" || 
    theirSession === "AcLab Session Full2" || 
    theirSession === "AcLab Session Full3" || 
    theirSession === "AcLab Session Full4" || 
    theirSession === "AcLab Session Full5" || 
    theirSession === "AcLab Session Full6" || 
    theirSession === "AcLab Session Full7") {
  MailApp.sendEmail(theirEmail, subject, message, cosmetics);
}

或者,您可以将所有选项添加到数组中,并使用indexOf() 在其中查找所需的值:

var sessions = ["AcLab Session Full1", 
                "AcLab Session Full2", 
                "AcLab Session Full3", 
                "AcLab Session Full4", 
                "AcLab Session Full5", 
                "AcLab Session Full6", 
                "AcLab Session Full7"];
if (sessions.indexOf(theirSession) >= 0) {
  MailApp.sendEmail(theirEmail, subject, message, cosmetics);
}

【讨论】:

  • 非常感谢!我使用了 if 条件的简单代码,它可以工作!你帮助一位老师为她的学校找出了一个大问题,我很感激(我开始有点理解剧本中发生的事情)。非常感谢!
  • 我很高兴它有帮助!在这种情况下,请考虑接受它作为问题的答案:stackoverflow.com/help/someone-answers
猜你喜欢
  • 2018-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-03
  • 2021-05-12
相关资源
最近更新 更多