Reputation: 2164
I have a function that updates a spreadsheet. It runs every morning and, every time it does, it creates 4 triggers. I also have time-driven triggers, which I want to keep there.
Since there is a limit on the triggers, I need to remove the triggers created by the function (while maintaining the other ones). However, when I run this:
function Triggers () {
Logger.log(ScriptApp.getProjectTriggers())
}
I get this as a response:
[Trigger, Trigger, Trigger, Trigger, Trigger, Trigger, Trigger, Trigger]
How can I identify, of these, the ones created by that function so I can eliminate those only?
Upvotes: 1
Views: 1657
Reputation: 1
Our solution has been the following:
var triggers = ScriptApp.getProjectTriggers();
for (i in triggers){
Logger.log(triggers[i].getUniqueId());
}
Then, identify the unique ID(s) from the trigger you want to preserve (usually a positive number). Say the ID = 123456789
var triggers = ScriptApp.getProjectTriggers();
for (i in triggers){
if (triggers[i].getUniqueId() != 123456789) {
ScriptApp.deleteTrigger(triggers[i])
}
}
Upvotes: 0
Reputation: 2164
I used this code:
function Triggers () {
var triggers = ScriptApp.getProjectTriggers()
for (i in triggers)
if ((triggers[i].getHandlerFunction()) == "createStats") {
ScriptApp.deleteTrigger(triggers[i])
}
}
Upvotes: 2