0
votes

I have an IFTTT applet that will update cell C65 in my google sheet. I'd like that sheet to run a function submitData() whenever cell C65 is changed. As many know, however, the onEdit and onChange functions do not trigger from IFTTT actions, only from manual inputs.

I've learned this from searching for answers, and nobody seems to be able to explain a workaround. The strangest thing here is that when I first put it together today, it actually worked perfectly. I then swapped google accounts and made other changes that didn't relate to the code or IFTTT applet and all of a sudden it stopped working entirely, even when switching back to the correct google account.

This is the onEdit code that works for screen inputs but not when my IFTTT enters a value into the cell:

function onEdit(e){
  var cellAddress,cellAddressToTestFor;

  cellAddressToTestFor = 'C65';

  // Get cell edited - If it's C65 then do something
  cellAddress = e.range.getA1Notation();
  Logger.log('cellAddress: ' + cellAddress);

  if (cellAddress === cellAddressToTestFor) {
    //To Do - Code here if cell edited is correct
    submitData();
  };
}

Is there any way to get the IFTTT event to trigger my submitData function?

1
IFTTT puts the value to the Google Spreadsheet using Sheets API. So in this case, I thought that the OnChange event trigger could be used. So from onChange functions do not trigger from IFTTT actions, can I ask you about the method that you have tried the OnChange event trigger?Tanaike
I used the same code but substituted onChange. As I understand it though, onChange doesn't support the e.range call, so I don't know how to check the changed value's location to verify it's at C65C47 Man
Thank you for replying. I think that you might misunderstood about the OnChange event trigger. From your replying, I thought that you had been trying to use the OnChange event trigger as the simple trigger. Ref But, onChange() is not the simple trigger. So can you use the OnChange event trigger as the installable trigger and test it again? RefTanaike
How do you mean? I'm not sure how to use an installable trigger, or what that isC47 Man
Thank you for replying. I have to apologize for my poor English skill. In this case, how about checking the official document at developers.google.com/apps-script/guides/triggers/installable as shown in my replying? I think that English of the official document is better than me. I deeply apologize for my poor English skill.Tanaike

1 Answers

0
votes

So the 'on edit' trigger won't work with IFTTT changes, but the 'on change' installable trigger will. However, the event object passed by the On Change trigger does not contain 'range', so there's no way to easily check the edited cell's location. To do so:

function onChange(e){
  var cellAddress,cellAddressToTestFor;
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = ss.getActiveSheet();
  var activeSheetName = activeSheet.getSheetName();

  cellAddressToTestFor = 'C65';

  // Get cell edited - If it's C65 then do something
  cellAddress = activeSheet.getActiveRange().getA1Notation();
  Logger.log('cellAddress: ' + cellAddress);

  if (cellAddress === cellAddressToTestFor) {
    //To Do - Code here if cell edited is correct
    submitData();
  };
}