onOpen not executing?

后端 未结 4 1250
长发绾君心
长发绾君心 2021-01-24 00:48

Hi guys im trying to display a sidebar on my google sheets every time it is opened. I am using the onOpen function and calling the html page, but it is not executing. When i run

相关标签:
4条回答
  • 2021-01-24 01:29

    A simple trigger open function can't open a sidebar because it runs on AuthMode.LIMITED. You should use a function that runs on Auth.Mode.FULL to open a sidebar, like an installable trigger.

    I know that this isn't about add-ons but the following quote applies

    From https://developers.google.com/apps-script/add-ons/lifecycle#authorization_modes

    Note: Add-ons can't open sidebars or dialogs while executing in AuthMode.LIMITED. You can use menu items to open sidebars and dialogs since these run in AuthMode.FULL.

    The cannonical references are

    • https://developers.google.com/apps-script/guides/triggers/
    • https://developers.google.com/apps-script/guides/triggers/events
    0 讨论(0)
  • 2021-01-24 01:39

    See if this works

    function showSideBar() {
       SpreadsheetApp.getUi()
        .showSidebar(HtmlService.createTemplateFromFile('tipA')
            .evaluate()
            .setTitle('Some title'));
    }
    

    and use an installable onOpen trigger on this function. As the previous poster already mentioned, I also don't believe you can show a sidebar (which requires authorization) on a simple onOpen trigger (which doesn't require authorization).

    0 讨论(0)
  • 2021-01-24 01:50

    Maybe the user doesn't have permission to edit the SS? Google Developers says onOpen() only fires if the user who is visiting your sheet has permission to edit the SS.

    0 讨论(0)
  • 2021-01-24 01:52

    Google has (quite) recently restricted the functionality of onOpen triggers. One of the restrains is the impossibility to show a sidebar. There is no real workaround since installable triggers will only work for the user that created the trigger, not for the other users. Instead you will receive a error notification each time someone opens the document. The best solution I found is to create a button that one can use to open the sidebar, this is easier than a menu and obviously more visible. There is a referenced issue on that subject : https://issuetracker.google.com/issues/69238694

    0 讨论(0)
提交回复
热议问题