Reputation: 1167
I have a Google Sheets spreadsheet that's been working for months, and has no scripts associated with it. Recently I decided I'd like to log the date of change to a row, and that the onEdit() function could do that for me.
From the spreadsheet display, I selected Tools / Script Editor, which popped up an empty script with a myFunction() function.
I modified myFunction() to:
function onEdit(e) {
Logger.log("Something was edited.");
}
Then pressed Save and accepted the default progject name (Untitled project). I also tested this (Run) and it created a log entry.
Now when I edit any value in the sheet or add a new row, I would expect a log entry. But none appears.
Have I missed a step? What must one do in order to get a valid onEdit() to run?
Upvotes: 0
Views: 4395
Reputation: 15375
Make sure you run the onEdit(e)
function from the Apps Script UI using the play button (►) and authorise the script to run as you.
Upvotes: 1
Reputation: 50797
Your logs will be available at View>Stackdriver logging. View>Logs will only show logs executed in the current session (by clicking "Run"). Using console
class is preferred.
Upvotes: 1
Reputation: 44710
Disclaimer: I don't often work with the Script Editor in Google Sheets, nor Google Sheets itself, too often. There may be a better way to accomplish this.
In my experience, I've found you also have to explicitly add a trigger to your Script Editor project to get the events to fire correctly.
onEdit
method to execute the method you've written.Once your trigger is set up, the spreadsheet should now be running your method whenever an edit to the spreadsheet is made.
Upvotes: 2