Google 应用脚本触发器不起作用 [英] Google app script trigger not working

查看:28
本文介绍了Google 应用脚本触发器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发送电子邮件的谷歌应用程序脚本,我设置了一个触发器,以便它在每次提交表单时发送电子邮件.问题是触发器在最初的几分钟内工作得很好,但即使在输入正确的数据之后也是如此.脚本不发送邮件,我必须手动按下脚本的执行按钮.这是我的代码

I have a google app script which sends email, and i have set a trigger such that it sends email on every form submit. The problem is the trigger works perfectly fine for initial few minutes, but later even after entering correct data. The script does not send the mail, i have to manually press the execution button of the script. Here is my code

var EMAIL_SENT = "EMAIL_SENT";
function sendEmailsapp() {
  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, 1, numRows,8)
  // 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[4];  // First column
    var message = row[5];       // Second column
    var emailSent = row[7];  // Third column
    var money=row[6]
    if (emailSent != EMAIL_SENT) {  // Prevents sending duplicates
      var subject = "You have been registered for follwoing events:-";
      var event;

      MailApp.sendEmail(emailAddress, subject, "Please bring your college id and copy of this mail either in phone or printed paper"+
                        "

"+"Name:-"+row[1]+"
"+"USN:-"+row[2]+"
"+"Mobile:-"+row[3]+"
"+"Event:-"+ message+"
Money status:-"+money+"You registered on"+row[0]);
        sheet.getRange(startRow + i, 8).setValue(EMAIL_SENT);


      // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush();
    }
  }
}

代码运行良好.唯一的问题是触发器.

The code works fine. The only problem is triggers.

这是我的触发器的图像.sendEmailsapp 是触发器,而 sendEmailsweb 是另一个触发器,它也有同样的问题.

Here is the image of my trigger. sendEmailsapp is the trigger, and sendEmailsweb is another trigger which also suffers from same problem.

这里是日志

我唯一的问题是触发器没有被触发,与发送的电子邮件无关.

My only Problem is the trigger is not getting triggered, it is not with the email being sent.

推荐答案

我的触发器和你的不一样,即使脚本是正确的.

My trigger wasn't working just like yours, even though the script was correct.

解决方案非常愚蠢.我删除了触发器并添加了一个新触发器.完全相同的触发器.

The solution was very stupid. I deleted the trigger and added a new one. Exactly the same trigger.

这篇关于Google 应用脚本触发器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆