Does Google Sheet onEdit trigger is being executed after sheet is recalculated

Viewed 111

I have a Spreadsheet with onEdit trigger. A1 is used by other cells, say B1.

The trigger "listen" to A1 modification, and than gets B1 new value to perform its job.

Question is it guarantees that B1 has been already recalculated when onEdit is fired? for example:

Cell B1 contains the formula =A1+1

Now 1 is typed into A1

function onEdit(e){

  var changeRng  = e.range;

  if (changeRng.getA1Notation() == "A1") {
    //Read value from B2
    var b1 = SpreadsheetApp.getActive().getActiveSheet().getRange(1, 2).getValue();
  }

}

Is variable b1 guarantee to be 2?

1 Answers

If onEdit() is triggered by an edit of A1 there is no garantee that B1 has finished recalculating before onEdit() is fired, especially if the recalculation of B1 is time intensive.

I recommend you to incorporate at the beginning of you onEdit function a Utilities.sleep() call to give the value in B1 enough time to recalculate.

Related