Search code examples
google-apps-scriptgoogle-sheetstriggers

Google Apps Event changeType undefined in Google Sheet


function onEdit(e) {
  Browser.msgBox(e.changeType);
  if (e.changeType == 'EDIT') {
    ...
  }
}

The event fires successfully when a sheet cell is changed from empty to a number, but the msgBox output shows "undefined".

Shouldn't e.changeType contain 'EDIT'?

I'm using this reference: https://developers.google.com/apps-script/understanding_events


Solution

  • The documentation you refer to does not concern the simple onEdit trigger, it works with the installable onChange trigger which is completely different.

    You should rename your function to whatever name you want (but not "onEdit") and add an onchange trigger from the script Editor menu /Resources/current project trigger/

    Then if you want to know what value is returned in the event info you can use a code like this :

    function testonChange(e) {
      Browser.msgBox(Utilities.jsonStringify(e));
    }
    

    And you'll see exactly how the event is considered.