admin管理员组

文章数量:1391934

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');
}

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');
}
Share Improve this question edited Oct 15, 2018 at 16:54 Wicket 38.8k9 gold badges80 silver badges195 bronze badges asked Oct 15, 2018 at 7:08 stevesteve 16713 bronze badges 4
  • Try LockService ? – TheMaster Commented Oct 15, 2018 at 9:32
  • I added LockService but it didn't work... – steve Commented Oct 15, 2018 at 10:55
  • Edit to show 1. modified code 2. Script execution log(view>executions) with relevant explanations and error logs – TheMaster Commented Oct 15, 2018 at 11:04
  • @steve you seem to be right. I did it slightly different and simply typed a character and return several times in a row quickly. The cursor advances to the next row and again the next row but seems to skip every other setValue("edited"). {e.range.offset(0,1,1,1).setValue("edited");} – TheWizEd Commented Oct 15, 2018 at 14:18
Add a ment  | 

1 Answer 1

Reset to default 9

This is a known limitation of onEdit.

From a ment 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.

本文标签: javascriptFailure of calling Google App Script onEdit function many times in a secondStack Overflow