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!