7

I am trying to fire an onChange event and it is not working.

I have the following simple code:

function onChange(){
  Logger.log("onChange event fired");
}

function onEdit(){
  Logger.log("onEdit event fired");
}

https://developers.google.com/apps-script/understanding_events

According the this document, the onChange event should be fired when a row is inserted. It does not get fired. The onEdit function gets fired when you manipulate a cell, but I need an event to be fired when the user inserts a row as well.

Any thoughts?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Ramuk
  • 217
  • 1
  • 4
  • 9
  • that's an example of how a function works, if you want the onchange event for a particular cell, you should consult the api. – 4m1r Mar 17 '14 at 18:45
  • 1
    https://developers.google.com/apps-script/understanding_triggers Show me where you've got onChange trigger? – Mr.TK Mar 17 '14 at 18:45
  • Take a look at [this](http://stackoverflow.com/questions/17358808/google-apps-script-run-when-spreadsheet-is-change-by-another-script) so. – Jacobvdb Apr 08 '14 at 03:31

3 Answers3

11

Try to use signatures with one parameter:

function onChange(e){
  Logger.log("onChange event fired");
}

function onEdit(e){
  Logger.log("onEdit event fired");
}

And then register those functions in ScriptEditor:

enter image description here

Mario
  • 241
  • 1
  • 9
5

onChange is an install-able trigger. Use the following function to install the trigger.

    function createSpreadsheetChangeTrigger() {
    var ss = SpreadsheetApp.getActive();
    ScriptApp.newTrigger('onChange')
      .forSpreadsheet(ss)
      .onChange()
      .create();
    }  
3

In the script editor I clicked the Resources menu and selected 'All your triggers' from there I was able to register my onChange function to actually be triggered on change of the spreadsheet.

Edit: People were telling me to do this with code, I couldn't get that to work. Found the gui method buried in the docs.

Ramuk
  • 217
  • 1
  • 4
  • 9
  • Why do you need onChange event to fire? What can you get from the event ojbect? https://stackoverflow.com/questions/67931041/google-sheet-how-to-get-the-actual-change-when-onchange-event-fires/67931286#67931286 – shenkwen Jun 11 '21 at 12:11