0

Does anyone know how I can change the below function to postEdit rather than onEdit?

I am trying to set this in an autoSort function so that the sheet will be edited only after all values in an inline row, in columns A-F, have been entered rather than been edited straight after values in only column A have been entered?

function onEdit(event) {
  var editedCell;

  activeSheet = SpreadsheetApp.getActiveSheet();
  editedCell = activeSheet.getActiveCell();

  if (editedCell.getColumn() == SORT_COLUMN_INDEX) {
    autoSort(activeSheet);
  }
}
0

Google Apps Script hasn't a postEdit trigger but you can achieve the result you are looking for by using JavaScript conditions.

First, some basic tips,

  1. always use var to declare your variables otherwise they will be declared on the global scope and this could lead to some problems.
  2. make use of the event properties, in this case, instead of getActiveCell() use e.range to get the edited Range object.

The following onEdit function is triggered every time a user makes an edit to the spreadsheet. The autosort function is called, when NOT all values of the corresponding row from A to F are filled up, otherwise it is not.

function onEdit(e){
  if(e.columnStart > 6) return; // If the edited range is on column 7 or beyond, do nothing
  // Check if all the cells in the row are already filled up
  var sheet = e.range.getParent();
  var currentRecord = sheet.getRange(e.rowStart,1,6).getValues()[0];
  var recordComplete = currentRecord.every(function(value){ return value !== ''});
  if(recordComplet){
    // Call the autosort function
      autosort(sheet);
  } else {
    // Do nothing
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.