4

I have a IFTTT trigger set to add a row to a spreadsheet when I send an SMS to IFTTT.

I'm attempting to write a Spreadsheet Google Apps Script to add a corresponding row to an additional sheet in the spreadsheet. It should fire when IFTTT adds a row, but so far it's only firing when I manually change something in the spreadsheet, not when IFTTT does it.

I want basically the same functionality as this question. I used Mogsdad's code from that answer to make a fakeEvent and hand it to an onEdit() function, but I still can't get it to fire automatically.

Is there some special way to implement onChange when the change in question is going be made 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 would know that it was the onChange trigger firing, not the onEdit. I also took out the stuff that dealt with simultaneous events, because I don't anticipate any.

Like I said, this script works great when editing the sheet myself, but not after an IFTTT change. Any ideas? Thanks!

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • 2
    onChange and onEdit unfortunately are only called when changes are made from the web sheeta version (not from api or mobile apps). othwr questions deal with how to detect changes in other ways (ive answered one recently see my profile answers) – Zig Mandel Aug 04 '15 at 22:19
  • Ah I was hoping that wasn't the case. Oh well. I saw your 1min interval trigger idea on a similar question, so I'll use that. Thanks! – Andrew Marshall Aug 05 '15 at 02:53

0 Answers0