I'm using a Google spreadsheet. I'm attempting to create an onChange
trigger that will activate a script when any sheet is added or deleted. I was able to get the script to work when a new sheet is added using changeType === "INSERT_GRID"
. However when I'm using changeType === "REMOVE_GRID"
the script does not activate when a sheet is deleted. Maybe I'm misunderstanding what REMOVE_GRID
does?
Here is a simplified version of what I was trying to achieve:
function deleteSheet(e) {
if (e.changeType === "REMOVE_GRID") {
e.source.getSheetByName("Sheet1").getRange(1, 1).setValue("Deleted a sheet");
}
}
I did change the trigger to: deleteSheet --> spreadsheet --> onChange
Any help would be appreciated! Also this is my first time posting so I apologize in advance for any formatting errors. Thanks!
Best Answer
You can check to see what type of event is getting passed into that trigger by adding:
Browser.msgBox(Utilities.jsonStringify(e))
at the top. This will also confirm that the function is getting triggered.
From: https://stackoverflow.com/questions/17750589/google-apps-event-changetype-undefined-in-google-sheet/17751347#17751347