Google Apps Script stops functioning after years of successful operation in Sheets

I’ve been using a Google Apps Script for several years that automatically moves rows from one sheet to another. The script monitors when someone puts an “x” in a specific column on my “SalesPipeline” sheet. When this happens, it copies that entire row to my “CLOSED” sheet and removes it from the original location.

This automation worked perfectly for a long time, but recently it started throwing an error. The execution transcript shows:

TypeError: Cannot read properties of undefined (reading ‘source’)
handleEdit @Script.gs.6

function handleEdit(e) {
  // source data lives in sheet called SalesPipeline  
  // destination sheet for transfers called CLOSED
  // check column is col 20 (column T)
  var workbook = SpreadsheetApp.getActiveSpreadsheet();
  var currentSheet = e.source.getActiveSheet();
  var editedCell = e.source.getActiveRange();

  if(currentSheet.getName() == "SalesPipeline" && editedCell.getColumn() == 20 && editedCell.getValue() == "x") {
    var rowNumber = editedCell.getRow();
    var totalColumns = currentSheet.getLastColumn();
    var destinationSheet = workbook.getSheetByName("CLOSED");
    var destinationCell = destinationSheet.getRange(destinationSheet.getLastRow() + 1, 1);
    currentSheet.getRange(rowNumber, 1, 1, totalColumns).copyTo(destinationCell, {contentsOnly: true});
    currentSheet.deleteRow(rowNumber);
  }
}

What could be causing this sudden failure?

Your script’s getting called without a proper event object. This usually happens after Google updates their backend or when triggers get reset. Besides the trigger stuff others mentioned, check if you’ve changed anything in your spreadsheet structure or formulas lately - that might be firing the function unexpectedly. I had the same problem when array formulas started triggering edit events without proper context. Wrap your initial variable declarations in a try-catch block to pinpoint exactly where it’s failing. Also check the trigger logs in Apps Script dashboard - you might have multiple executions running at once, which can mess up the event object.

Had this exact problem about six months ago with a script that’d been working perfectly for years. Your script’s getting triggered when the event object ‘e’ doesn’t have the properties it expects. This happens when you run the function manually from the script editor or when some other trigger calls it without passing the proper event object. Fixed it by adding a quick check at the start of the function to make sure the event object exists and has what you need. Just add ‘if (!e || !e.source) return;’ right at the beginning of your handleEdit function. Stops the script from crashing when called without proper event context but still works fine during real edit events.

your trigger prolly got corrupted or duplicated. I’ve seen this when google updates break old triggers. delete all your triggers in the script editor, then create a new onEdit trigger from scratch. also make sure u didn’t accidentially create multiple triggers for the same function - that causes weird behavior.