0

I have some code which needs to execute one function based on an hourly trigger, then another function exactly one hour after the first one. Like this:

function main() {
  firstFunction();
  ScriptApp.newTrigger('secondFunction')
  .timeBased()
  .after(60 * 60 * 1000) // 60 mins * 60 s * 1000 ms
  .create();
}

This is working fine. I just noticed though that the triggers build up in "my triggers" of the google apps script console. Is there any way to delete the trigger after execution?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Alexander Soare
  • 2,825
  • 3
  • 25
  • 53
  • I always check to see if there are triggers with same function name before creating new ones – Cooper Apr 23 '20 at 14:06

1 Answers1

2

After execution,

function secondFunction(e){
  ScriptApp.deleteTrigger(
    ScriptApp.getProjectTriggers().find(
      trigger => trigger.getUniqueId() === e.triggerUid
    )
  );
}
TheMaster
  • 45,448
  • 6
  • 62
  • 85