I have set a trigger to run 9am daily and post to the channel in slack via a webhook, although set to run everyday I am getting duplicate returns in a channel.
Here is the function:
function setTrigger() {
ScriptApp.newTrigger('sendBirthdayMessage')
.timeBased()
.everyDays(1)
.atHour(9)
.nearMinute(00)
.create()
}
What ends up happening is that it runs on multiple times.
Is there a way to check if a trigger for that day has already been executed before proceeding to init a new trigger?
CodePudding user response:
What your screenshot show is that there are 3 triggers in your Apps Script project (not three executions of the same trigger, three different triggers). So most likely, the same function is being called 3 times a day.
You can list the triggers in your project with ScriptApp.getProjectTriggers()
. This returns a list of Triggers. And then you call call the getHandlerFunction()
method on them to see what function they're gonna run (doc).
Also, you can delete a trigger with ScriptApp.deleteTrigger(THE_TRIGGER)
(not its name, the Trigger object itself).