OnChange not firing when table is being edited by IFTTT

I have an IFTTT trigger to add a row to a spreadsheet when I am sending an SMS to IFTTT.

I am trying to write a Google Apps Script Spreadsheet to add a matching row to an extra sheet in a spreadsheet. It should fire when IFTTT adds a row, but so far it does fire when I manually change something in the spreadsheet, not when IFTTT does it.

I want basically the same functionality as this question . I used the Mogsdad code from this answer to create a fakeEvent and pass it to the onEdit () function, but I still can't get it to start automatically.

Is there some special way to implement onChange when the change question is done by a script?

Here's the relevant code:

function createChangeTrigger() {
  var sheet = SpreadsheetApp.getActive();
  ScriptApp.newTrigger("playCatchUp")
   .forSpreadsheet(sheet)
   .onChange()
   .create();
}

// Installable trigger to handle change or timed events
// Something may or may not have changed, but we won't know exactly what
function playCatchUp(e) {
  // Check why we've been called
  if (!e)
    Logger.log("playCatchUp called without Event");
  else {
    if (e.hasOwnProperty("changeType")) {
      Logger.log(e.changeType);
    }    
  }

  // Build a fake event to pass to onEdit()
  var fakeEvent = {};
  fakeEvent.source = SpreadsheetApp.getActiveSpreadsheet();
  var lastRow = fakeEvent.source.getActiveSheet().getLastRow();
  fakeEvent.range = fakeEvent.source.getActiveSheet().getRange(lastRow, 1, 1, 3);
  Logger.log(fakeEvent.range.getRow());
  changeIt(fakeEvent);
}

      

I changed the onEdit () call at the end to changeIt () so that I know it was the onChange trigger firing and not onEdit. I also took material that dealt with simultaneous events, because I don't expect.

As I said, this Script works fine when editing a sheet, but not after changing the IFTTT. Any ideas? Thank!

+3


source to share





All Articles