google-apps-scripttriggers

Google Sheets Time-Driven trigger didn't execute


I've setup a Google Script that is time-driven, to be executed daily. On most days, it executes, but on some, it just doesn't execute at all. As you can see in the image below, the Import CSV just didn't run on the 24th or 25th.

As you can see, it didn't execute on 25 or 26

Do you have any idea why this could be happening? I'll add the code on the bottom so you can take a look and help me understand. But please note that the code works when executed, but, it seems not to execute. At times, when it executes, it says that it has exceeded the quota but works anyway.

Basically all the script does is go over to the e-mail and grab the required csv file from the e-mail, which it then appends over on the Google Sheet.

function LaredouteDownloadIntake() {
  
  var sheetId="1HMlwxNS99p75IdRHXo1QoeWDWEz0gbTnqNufCfmqyzc";
    
  var threads = GmailApp.search("from:no-reply@omniture.com subject:Classeur Excel (labelium_it.xlsx) in:inbox newer_than:1d filename:.csv");
  var message = threads[0].getMessages()[0];
  var attachment = message.getAttachments()[3];
  
  attachment.setContentTypeFromExtension();
  Logger.log(attachment.getContentType());
  
  if (attachment.getContentType() === "text/csv") {
    
    console.log("Funcion checking if csv exists");
    var sheet = SpreadsheetApp.openById(sheetId).getSheetByName('LaredouteITAdobe');
    var csvData = Utilities.parseCsv(attachment.getDataAsString(), ",");
    
    var column = sheet.getRange('A:A');
    var values = column.getValues(); // get all data in one call
    var ct = 0;
    while ( values[ct][0] != "" ) {
      ct++;
    }
    
    sheet.getRange(ct, 1, csvData.length, csvData[0].length).setValues(csvData);
    
    var threads = GmailApp.search("from:no-reply@omniture.com subject:Classeur Excel (labelium_com.xlsx) in:inbox newer_than:1d filename:.csv");
    var message = threads[0].getMessages()[0];
    var attachment = message.getAttachments()[3];
        
    attachment.setContentTypeFromExtension();
    
    Logger.log(attachment.getContentType());
    
    if (attachment.getContentType() === "text/csv") {
      console.log("Funcion checking if csv exists");
      var sheet = SpreadsheetApp.openById(sheetId).getSheetByName('LaredouteCOMAdobe');
      var csvData = Utilities.parseCsv(attachment.getDataAsString(), ",");      
      var column = sheet.getRange('A:A');
      var values = column.getValues(); // get all data in one call
      var ct = 0;
      while ( values[ct][0] != "" ) {
        ct++;
      }
      
      sheet.getRange(ct, 1, csvData.length, csvData[0].length).setValues(csvData);
    }
  }
}

Trigger settings are: | | | |---|---| |Choose which function to run | LaredouteDownloadIntake| |Which runs at deployment 1 | head | |Select event source | Time-driven | |Select type of time based trigger| Day Timer |Select time of day | 5am to 6am |


Solution

  • This appears to be a bug!

    I have taken the liberty of reporting this on Google's Issue Tracker for you, detailing the behaviour:

    You can hit the ☆ next to the issue number in the top left on the page which lets Google know more people are encountering this and so it is more likely to be seen to faster.