onEdit()
will keep triggering when you're working in the sheet where you started your script (where it has been bound), but if you try deploying it as a Sheet add-on, you'll need to explicitly install it as a trigger. Note that it must still be named onEdit
, not myEditingFunction
.
In order to test your triggering functionality, you must first deploy your Sheet add-on as some sort of restricted app (to bypass Google's review) and deploy it to a sheet outside your test sheets, otherwise your trigger installation will cause exceptions: Exception: The Add-on attempted an action that is not permitted in Test as Add-on mode. To use this action, you must deploy the Add-on.
Here's the way I was installing my onEdit
triggers:
var sheetName = SpreadsheetApp.getActiveSpreadsheet().getName();
var documentProperties = PropertiesService.getDocumentProperties();
var editingFlag = documentProperties.getProperty(TRIGGER);
if (editingFlag == null) {
try {
trigger = ScriptApp.newTrigger("onEdit").forSpreadsheet(e.source).onEdit().create();
documentProperties.setProperty(TRIGGER, "");
} catch (e) {
console.error("Caught exception on attempting to save trigger:" + e);
}
} else {
console.log("onEdit trigger is already listening for edits to sheet " + sheetName);
}