'How to delete triggers that own by other users in Google Apps Script?

I have an installable trigger that is supposed to created once. But I found out that some of my coworkers have rerun my code and recreated another 3 triggers that are exactly the same. I felt so silly that I didn't add any conditional statement for that...

Anyway, now I want to delete these extra triggers. But I cannot find the delete/edit button on the console UI of the GAS project. And I've also tried ScriptApp.getProjectTriggers(), but it lists the triggers of the project that are only owned by me.

How can I delete these extra triggers created by others (owned by other users)? Or can I restart my project from a clean start again?



Solution 1:[1]

In addition to @Alan Wells comment: no, you definitely cannot. What you can do, though, is make your users run a remover function on their behalf with something like this (if your script is container-bound, add it to onOpen() trigger if you have one, or to any other function that you expect to be called by others):

function deleteAllTriggers() {

  var ts = ScriptApp.getProjectTriggers();
  
  ts.forEach(function(trigger){
    
    var handlerName = trigger.getHandlerFunction();

    if(handlerName === 'yourFunctionName') { //check if you are deleting target trigger;
      ScriptApp.deleteTrigger(trigger);
      Utilities.sleep(1000); //wait (in this sample 1s) to avoid "too many times" error;
    }

  });

}

ES6-style:

const deleteAllTriggers = () => {
    const triggers = ScriptApp.getProjectTriggers();
    triggers.forEach((trigger) => ScriptApp.deleteTrigger(trigger));
};

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1