本文介绍了如何在Google脚本中使用onOpen多次安装触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不太了解如何避免两次添加相同的触发器.除了将数据存储在属性中并每次进行比较之外,还有其他方法吗?
I don't really understand how to prevent adding the same trigger twice. Except storing data in properties and comparing each time are there any other ways?
推荐答案您可以使用 getProjectTriggers ,然后将其循环并检查是否需要.
You can get project triggers with getProjectTriggers, then loop them and check for needed one.
例如,如果要检查onEdit触发器是否已设置:
For example if you want to check if onEdit trigger already set:
var allTriggers = ScriptApp.getProjectTriggers(); var editTriggerSet = false; for (var i = 0; i < allTriggers.length; i++) { if (allTriggers[i].getEventType() == ScriptApp.EventType.ON_EDIT) { editTriggerSet = true; break; } } // log the result Logger.log(editTriggerSet);更多推荐
如何在Google脚本中使用onOpen多次安装触发器?
发布评论