When I open my spreadsheet and choose Extensions > Apps Script, the list shows two script projects. They contain onEdit()
simple triggers and onChange()
installable triggers.
This is the first script project:
function onEdit(e) {
console.log('onEdit() #1')
}
function onEdit(e) {
console.log('onEdit() #2')
}
function installableOnChange(e) {
console.log('installableOnChange() #1')
}
This is the second script project:
function onEdit(e) {
console.log('onEdit() #3')
}
function onEdit(e) {
console.log('onEdit() #4')
}
function installableOnChange(e) {
console.log('installableOnChange() #2')
}
I have been able to determine which functions run when the built-in "on edit" and installable "on change" triggers fire using console.log
, but would like to know how to determine that when writing the code, without requiring as much testing and logging?
In other words, how do I know which copies of these functions will run when the user edits the spreadsheet?
If you have multiple copies of a simple trigger function like onEdit()
in the same script project, only one of them will be active. Specifically, it will be the one that was declared last. If there are multiple script files in the same project, they are evaluated in the order they appear in the left-hand file list pane, or alphabetically, depending on whether you are using the new Chrome V8 script runtime or the legacy Rhino runtime.
If you have the same simple trigger like onEdit()
in multiple script projects that are each bound to the same spreadsheet file, every copy will be active.
Installable triggers are created separately for each script project. To determine which installable triggers are active, open each script project in turn and click the clock icon 🕓 in the left-hand tool pane.