Google app script trigger not working

user4312531 picture user4312531 · Feb 24, 2015 · Viewed 24.2k times · Source

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"+
                        "\n\n"+"Name:-"+row[1]+"\n"+"USN:-"+row[2]+"\n"+"Mobile:-"+row[3]+"\n"+"Event:-"+ message+"\nMoney 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.

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

here is the log enter image description here

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

Answer

Allure Web Solutions picture Allure Web Solutions · Mar 31, 2017

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.