I’m currently working on a Google Sheets project, and I want to automatically insert today’s date into a designated column whenever any changes are made to that row. The key point is that the date should only populate if there’s currently no date in that column.
I created a Google Apps Script function to manage this action, but I’m experiencing some challenges. Even the basic debug messages I’ve added are not functioning, which suggests there may be a deeper issue with how I’ve set it up.
Here’s what I’ve implemented:
/**
* Auto-fills timestamp when row data is modified
*/
function onEdit(e){
var activeSheet = e.source.getActiveSheet();
var testCell = activeSheet.getRange(5,5);
testCell.setValue("Testing"); // This should appear but doesn't
var modifiedCell = activeSheet.getActiveRange();
var timestampColumn = 1;
var timestampCell = activeSheet.getRange(modifiedCell.getRow(), timestampColumn);
testCell.setValue(modifiedCell.getColumn());
if(timestampCell.getValue() == "" && modifiedCell.getColumn() != timestampColumn){
timestampCell.setValue(new Date());
}
}
Can anyone help me figure out what’s going wrong? It seems like the script isn’t triggering as expected.
looks like your script isnt running at all which usually means the trigger isnt set up right. make sure you saved the script as onEdit (not OnEdit or onedit) and that your sharing the sheet correctly. also try refreshing the sheet after saving script
Your function appears correct but there’s a common gotcha with onEdit triggers that caught me when I first started working with them. The trigger only fires when you manually edit cells through the spreadsheet interface, not when values are changed programmatically or when you run the function from the script editor. If you’re testing by clicking the run button in Apps Script, nothing will happen because there’s no edit event. Try making an actual edit to any cell in your sheet and see if the debug message appears in cell E5. Also worth checking that your script is bound to the correct spreadsheet - if you created it as a standalone script instead of a container-bound one, the trigger won’t work properly with your sheet.
The issue is likely with the getActiveRange() method in your script. When onEdit triggers, there might not be an active range selected, which can cause the function to fail silently. Try replacing getActiveRange() with e.range instead, since the event object already contains the range that was edited. Also, your script overwrites the test cell twice which might be masking debugging output. I had similar problems when I started with Apps Script - the event-driven functions behave differently than regular functions you might test manually. Make sure you’re actually editing cells in the sheet to trigger the function, not just running it from the script editor.