Zak*_*Zak 2 add-on google-apps-script
是否可以测试使用 DocumentProperties 的 Google Apps 脚本?该测试文档似乎表明这是可能的:
如果您的加载项使用属性服务,则属性将在下次运行测试配置时保持可用并保持可用。
但是,当我尝试使用 DocumentProperties 时,出现以下错误:
Google Apps Script: You do not have permission to call getDocumentProperties
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试的代码:
function appFolderExists(){
PropertiesService.getDocumentProperties().getProperties();
return true;
}
function onOpen() {
FormApp.getUi().createMenu('My Addon')
.addItem('My Addon', 'showSidebar')
.addToUi();
if(!appFolderExists()){
createAppFolder();
}
}
Run Code Online (Sandbox Code Playgroud)
我的插件目前部署为测试(用于表单)。它已安装但未启用。
我想添加更多的逻辑appFolderExists,但我一直被卡住,因为我看不到访问 DocumentProperties。我做错了什么还是这只是测试插件的不便限制?
该问题是由测试已安装但未启用的插件引起的。因此在 authmode.None 中运行代码,在此模式下您无法访问文档属性
解决方案:
1)在安装和启用的情况下运行测试
2)确定authmode并运行相关代码:
function open(e){
if (e.authMode == ScriptApp.AuthMode.NONE){
// Code that does not access document properties
} else {
var prop = PropertiesService.getDocumentProperties().getProperties();
// Some code that uses document properties
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
343 次 |
| 最近记录: |