Search code examples
web-applicationsgoogle-apps-scriptgoogle-sheets-apigoogle-sheets-query

Google Sheets web app - Function execution inside a doGet() function


I coded a function FillMissingEvents() that basically edit missing data on the last row of a datalogger I built using Google Sheets web app.

When calling the function manually, it works well.

Is it possible to execute my function automatically after every execution of doGet() ?

I cannot find a way to call it other than : FillMissingEvents();

Also is the logging capabilities working in doGet() ? Cannot make it work.

Thanks !

function FillMissingEvents(){
  Logger.log("Execution started");

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  //give your sheet name below instead of Sheet1
  var sheet = ss.getSheetByName("Sheet1");

  var datarange = sheet.getDataRange();
  var lastrow = datarange.getLastRow();
  var lastcolumn = datarange.getLastColumn();
  for (i=1;i<=lastcolumn;i++) {

  var testvalue = sheet.getRange(lastrow, i).getValue();

    if (typeof testvalue == 'string' && testvalue=="")
     {
      var newvalue = sheet.getRange(lastrow - 1, i).getValue();
      sheet.getRange(lastrow, i).setValue(newvalue);
    }  

  }
}

function doGet(request) {

  if(request != null) {

//******* CODE

    }
FillMissingEvents();
}

Edit : I was publishing the Web app without incrementing the version. Works perfect now ! Thanks !


Solution

  • Answer from the comments:

    I was publishing the Web app without incrementing the version.