如何在Google脚本中使用onOpen多次安装触发器?

编程入门 行业动态 更新时间:2024-10-27 00:24:58
本文介绍了如何在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多次安装触发器?

本文发布于:2023-10-23 18:46:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   脚本   如何在   Google   onOpen

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!