google-sheetsgoogle-apps-scripteventtrigger

How to use SpreadsheetApp.Spreadsheet.getChanges method?


I'm trying to use this method in google apps script in the function that is triggered with OnChange event.

function sendResultsEmail(e) {
  const content = e.source.getChanges.toString();
  console.log(content);
}

This prits out function () { [native code] }

But when I use it this way e.source.getChanges(), I get an error

Exception: The parameters () don't match the method signature for SpreadsheetApp.Spreadsheet.getChanges.
    at sendResultsEmail(TriggerCreation:13:40)

The thing is, there is no documentation for this method anywhere. And yet, e.source.toString() shows that it exists.

Trigger creation:

function setupTrigger() {
  ScriptApp.newTrigger('sendResultsEmail')
    .forSpreadsheet('REDACTED')
    .onChange()
    .create();
}

I don't even know if it's useful to my cause. What am I doing wrong?


Solution

  • Sending a bunch of different types to test it...

    function testGetChanges(){
      const s = SpreadsheetApp.getActive();
      [1, "1", new Date()].forEach((o) => {
        try {
          console.log(s.getChanges(o))
        } catch (e) {
          console.error(e)
        }
      })
    }
    

    The logs showed:

    { [Exception: The parameters (number) don't match the method signature for SpreadsheetApp.Spreadsheet.getChanges.] name: 'Exception' }
    { [Exception: The parameters (String) don't match the method signature for SpreadsheetApp.Spreadsheet.getChanges.] name: 'Exception' }
    { [Exception: The api method 'getChanges' is not available yet in the new version of Google Sheets.] name: 'Exception' }
    

    Apparently, The parameter type is date and it was probably used to get changes in a spreadsheet from a given date.

    Unfortunately, As the error says,

    The api method 'getChanges' is not available yet in the new version of Google Sheets.

    This seems like a legacy feature used in old Google sheets and wouldn't help anyone today.