首页 文章

我可以在Google Apps脚本中测试DocumentProperties吗?

提问于
浏览
1

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

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

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

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

这是我正在尝试的代码:

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

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

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

我想向 appFolderExists 添加更多逻辑,但我一直卡住,因为我无法访问DocumentProperties . 我做错了什么或者这只是测试插件的一个不方便的限制?

1 回答

  • 2

    该问题是通过测试已安装但未启用的添加引起的 . 因此在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
    }
    }
    

相关问题