如何在Google Apps脚本中删除其他用户拥有的触发器? [英] How to delete triggers that own by other users in Google Apps Script?

查看:106
本文介绍了如何在Google Apps脚本中删除其他用户拥有的触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应该安装一次的可安装触发器.但是我发现我的一些同事重新运行了我的代码,并重新创建了3个与之完全相同的触发器.我感到很傻,以至于我没有添加任何条件声明...

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

无论如何,现在我想删除这些额外的触发器.但是我在GAS项目的控制台UI上找不到删除/编辑按钮.而且我也尝试过ScriptApp.getProjectTriggers(),但是它仍然列出了仅由我拥有的项目的触发器.

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 still list the triggers of the project that only owned by me.

如何删除其他人(其他用户拥有)创建的这些额外触发器?还是可以从头开始重新启动我的项目?

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

推荐答案

除了@Alan Wells评论-不,您

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风格:


ES6-style:

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

这篇关于如何在Google Apps脚本中删除其他用户拥有的触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆