当 Google 文档被容器绑定脚本复制时,如何获取其可安装触发器?
When Google document is copied with container-bound script, how to get its installable triggers?
问题
我的文档中附加了一个容器绑定脚本。
它有 onOpen
个可安装触发器,我需要在新创建的文档中获取脚本。
我发现最有效的方法是通过从原始文档复制来创建新文档。
The problem is, that the triggers are not copied with it.
条件:
- 简单的触发器不够,我需要使用需要授权的动作
- 我不想强迫我的用户为每个文档手动创建触发器
- 我不介意在以编程方式创建的菜单中单击按钮后是否创建了可安装触发器
我的想法:
我想以编程方式创建它 – 测试环境有问题。我收到一个错误:
The add-on attempted an action that is not permitted in Test as add-on
mode. To use this action, you must deploy the add-on.
据我了解,我需要将项目发布到商店才能使用它,但我不想这样做。
我不介意作为附加组件发布,但是 google 脚本 IDE 只提供作为 web Docs web 附加组件发布。
代码:
function onOpen(e){
DocumentApp.getUi() // Or DocumentApp, SlidesApp, or FormApp.
.createMenu('Custom menu')
.addItem('Open sidebar automatically', 'createTrigger')
.addToUi();
}
function createTrigger() {
var doc = DocumentApp.getActiveDocument();
ScriptApp.newTrigger('onOpenReal')
.forDocument(doc)
.onOpen()
.create();
}
function onOpenReal(e){
...something requiring authorization...
}
我想出了部分答案:
我认为不可能复制文档及其触发器,但我没有找到任何官方文档。
但是错误:
The add-on attempted an action that is not permitted in Test as add-on
mode. To use this action, you must deploy the add-on.
看似正常的环境是由 Google 应用程序脚本编辑器中保存的测试配置引起的。
要消除错误,您需要先删除 "Test as add-on" 选项中的所有测试配置。在此之前,即使以普通用户身份打开,系统也会将所有启动视为 "test"。
问题
我的文档中附加了一个容器绑定脚本。
它有 onOpen
个可安装触发器,我需要在新创建的文档中获取脚本。
我发现最有效的方法是通过从原始文档复制来创建新文档。
The problem is, that the triggers are not copied with it.
条件:
- 简单的触发器不够,我需要使用需要授权的动作
- 我不想强迫我的用户为每个文档手动创建触发器
- 我不介意在以编程方式创建的菜单中单击按钮后是否创建了可安装触发器
我的想法:
我想以编程方式创建它 – 测试环境有问题。我收到一个错误:
The add-on attempted an action that is not permitted in Test as add-on mode. To use this action, you must deploy the add-on.
据我了解,我需要将项目发布到商店才能使用它,但我不想这样做。
我不介意作为附加组件发布,但是 google 脚本 IDE 只提供作为 web Docs web 附加组件发布。
代码:
function onOpen(e){
DocumentApp.getUi() // Or DocumentApp, SlidesApp, or FormApp.
.createMenu('Custom menu')
.addItem('Open sidebar automatically', 'createTrigger')
.addToUi();
}
function createTrigger() {
var doc = DocumentApp.getActiveDocument();
ScriptApp.newTrigger('onOpenReal')
.forDocument(doc)
.onOpen()
.create();
}
function onOpenReal(e){
...something requiring authorization...
}
我想出了部分答案:
我认为不可能复制文档及其触发器,但我没有找到任何官方文档。
但是错误:
The add-on attempted an action that is not permitted in Test as add-on mode. To use this action, you must deploy the add-on.
看似正常的环境是由 Google 应用程序脚本编辑器中保存的测试配置引起的。
要消除错误,您需要先删除 "Test as add-on" 选项中的所有测试配置。在此之前,即使以普通用户身份打开,系统也会将所有启动视为 "test"。