需要根据问题答案向表单受访者发送电子邮件

时间:2021-06-30 00:23:05

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

我需要帮助!如果他们选择任何 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);}

1 个答案:

答案 0 :(得分:2)

如果您想在满足条件时发送电子邮件,则需要将该代码放在 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);
}
相关问题