The onEdit(e) trigger fires automatically whenever a user edits a cell in a spreadsheet. It receives an event object e with details about what changed, which sheet it was on, and the old and new values.
Always check the sheet name to avoid unintended behavior on other sheets:
functiononEdit(e){var sheet = e.source.getActiveSheet();if(sheet.getName()!=="Sales Tracker")return;// Only process edits on the Sales Tracker sheetLogger.log("Edit on Sales Tracker: "+ e.range.getA1Notation());}
Validating the Status Column
This example watches column G (Status) and highlights the row based on the value entered — green for Closed, yellow for In Progress, red for anything else:
The simple onEdit function cannot send emails or access external services. If you need that, create an installable trigger:
// Run this once to create an installable onEdit triggerfunctioncreateEditTrigger(){var ss =SpreadsheetApp.getActiveSpreadsheet();ScriptApp.newTrigger("onEditInstallable").forSpreadsheet(ss).onEdit().create();}// This installable version CAN send emailsfunctiononEditInstallable(e){var sheet = e.source.getActiveSheet();if(sheet.getName()!=="Sales Tracker")return;if(e.range.getColumn()!==7|| e.value!=="Closed")return;var row = e.range.getRow();var data = sheet.getRange(row,1,1,6).getValues()[0];var customerName = data[0];var customerEmail = data[1];var product = data[2];GmailApp.sendEmail( customerEmail,"Welcome to Acme Corp – Your "+ product +" is Active","Hi "+ customerName +",\n\nYour account is now active. Welcome aboard!\n\nBest,\nAcme Corp Team");Logger.log("Welcome email sent to "+ customerEmail);}