【问题标题】:Executing the correct enteries and ignoring the wrong entries(sending email) from a google form by google app script通过谷歌应用脚​​本从谷歌表单执行正确的输入并忽略错误的输入(发送电子邮件)
【发布时间】:2015-02-11 12:44:49
【问题描述】:

我有一个谷歌表单,它收集了一些细节和一个电子邮件 ID,但是如果电子邮件中的条目有误,脚本将失败并且不执行下一行,它就会卡在那里。现在我希望脚本忽略错误的条目并执行正确的条目。下面有我的代码。

var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;  // First row of data to process
  var numRows = sheet.getLastRow();   // Number of rows to process
  // Fetch the range of cells A2:B3

  var dataRange = sheet.getRange(startRow, 5, numRows, 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 = "You have been registered for follwoing events:-";
      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 7).setValue(EMAIL_SENT);
      // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush();
    }
  }
}

【问题讨论】:

    标签: google-apps-script google-sheets google-forms


    【解决方案1】:

    为此,您可以在这行代码之前添加一个 if 条件

    if(valid email address){     
    MailApp.sendEmail(emailAddress, subject, message);
    }
    else{continue;}
    

    验证电子邮件 ID 是否具有有效值。

    您也可以查看this的方法。

    希望有帮助!

    【讨论】:

    • 它告诉 Missing ) 条件之后。 (第 18 行,文件“代码”)就是 if 条件部分
    猜你喜欢
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多