GAS "On edit" trigger not running when edited from API
I was wondering if someone encountered this issue and thought of a workaround that isn't awful.
I have a trigger on Google Spreadsheets that is configured "on edit", and it works fine if the edit occurs manually (or via formula) from within the spreadsheet itself. However if I modify a cell externally from the Sheets API v4, the cell is changed but the function isn't triggered. Am I missing something, or Google simply doesn't support triggering when change comes from "outside"?
EDIT: As per @TheMaster's suggestion, I wrote:
function test_on_change(e){
console.log("Changed");
console.log(SpreadsheetApp.getActiveRange().getA1Notation());
}
The e
object is json
of the enum
that is described here.
Solution 1:
onChange
installable trigger works with edits made from sheets api. It is possible to get the edited range using .getActiveRange()
calls.
Solution 2:
As you can read in the Trigger Restrictions:
Script executions and API requests do not cause triggers to run. For example, calling Range.setValue() to edit a cell does not cause the spreadsheet's onEdit trigger to run.
In case you want to deploy the script as a Web App as Tanaike mentioned, you might want to check the documentation.