我可以在Google Apps脚本中测试DocumentProperty吗? [英] Can I test DocumentProperties in Google Apps Scripts?

查看:74
本文介绍了我可以在Google Apps脚本中测试DocumentProperty吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以测试使用DocumentProperties的Google Apps脚本?测试文档似乎表明这是可能的:

Is it possible to test a Google Apps Script that uses DocumentProperties? The testing documentation seems to indicate this is possible:

如果您的加载项使用属性"服务,则属性将保留并在下次运行测试配置时保持可用.

If your add-on uses the Properties service, properties will persist and remain available the next time the test configuration is run.

但是,当我尝试使用DocumentProperties时,出现以下错误:

However, when I attempt to use DocumentProperties, I get the following error:

Google Apps Script: You do not have permission to call getDocumentProperties

这是我正在尝试的代码:

This is the code I am trying:

function appFolderExists(){
    PropertiesService.getDocumentProperties().getProperties();
    return true;
}

function onOpen() {
    FormApp.getUi().createMenu('My Addon')
        .addItem('My Addon', 'showSidebar')
        .addToUi();
    if(!appFolderExists()){
        createAppFolder();
    }
}

我的插件当前已部署为测试(用于表单).已安装但未启用.

My addon is currently deployed as a test (for a form). It is installed but not enabled.

我想为 appFolderExists 添加更多的逻辑,但是由于看不到访问DocumentProperties,所以我一直陷入困境.我是在做错什么还是仅仅是测试插件的不便之处?

I want to add more logic to appFolderExists down the line, but I keep getting stuck since I can't seen to access the DocumentProperties. Am I doing something wrong or is this just an inconvenient limitation of testing addons?

推荐答案

问题是由测试已安装但未启用的附加组件引起的.因此,以authmode模式运行代码.无,在此模式下,您将无法访问文档属性

The issue is caused by testing the add on as installed but not enabled. Thus runs the code in authmode.None, in this mode you cannot access document Properties

解决方案:
1)在已安装并启用的情况下运行测试
2)确定 authmode 并运行相关代码:

Solutions:
1) Run the test as installed and enabled
2) Determine the authmode and run the relevant code:

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
}
}

这篇关于我可以在Google Apps脚本中测试DocumentProperty吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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