Failure of calling Google App Script onEdit functi

2020-02-01 09:23发布

问题:

I have been struggling with a strange behavior of onEdit function of Google Apps Script.

To my understanding, this onEdit event is fired every time a cell is edited. It is no problem when I edit a cell slowly like one cell for every 1 second. All events are fired for sure.

However, when I edit a few cells in a second very quickly, some of them aren't fired. So I want to make sure onEdit event is fired even when I edit cells very quickly. Below are my code, am I missing something?

I have been debugging for this whole day... Please help me out with this issue.

function onEdit(e){
  var as = SpreadsheetApp.getActiveSheet();
  var r = e.source.getActiveRange();
  var edditRow = r.getRow();
  console.log(edditRow);
  as.getRange(edditRow, 2).setValue('edited');
}

回答1:

This is a known limitation of onEdit.

From a comment by Eric Koleda, a Googler, to Only two onEdit trigger events can be queued at a time in New Sheets

You'll have to assume that onEdit triggers are best-effort, but may not catch all edits done to the spreadsheet.