Reputation: 21
I have a piece of code that runs on any edit in my google sheets that looks like this:
function onEdit(e) {
Browser.msgBox("I pop up on Edit!");
}
But it doesn't seem to work when it's deployed and published on the Chrome Web Store as an Add-On... I have Browser.msgBox in other methods that don't involve edit triggers and they work fine.
I have tried using modal dialogs, ui alerts, notes, html pop-ups, and toast messages in replacement of Browser.msgBox but they all don't work in the edit trigger functions.
The only reasoning I could find is edit triggers are not compatible with pop-up boxes in Google Spreadsheets Add-ons. Could I get some light shed on this?
Upvotes: 2
Views: 3585
Reputation: 529
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);
}
Upvotes: 1
Reputation: 201428
This is a sample.
function onEdit(e){
var ui = SpreadsheetApp.getUi();
ui.alert("I pop up on Edit! " + e.value);
}
If you want to know about the detail, please check https://developers.google.com/apps-script/reference/base/ui
Upvotes: 0