AlexB
AlexB

Reputation: 2184

Google Sheet add-on onInstall() and onOpen() not working

I am trying to create an add-on for Google Sheets, but running in the problem.

The add-on creates additional menu in "Add-on" menu using onOpen() function of Google Drive API, but it does not do that onInstall(). So I have been told to add the folloing

function onInstall(e) {
   onOpen(e)
}

now, what I have tried to do is the following, but it still does not work

    function onInstall() {
       SpreadsheetApp.getUi().createAddonMenu()
          .addItem('Browse My Add-on', 'browseMyAddOn')
          .addToUi();
    }

    function onOpen() {
        SpreadsheetApp.getUi().createAddonMenu()
          .addItem('Browse My Add-on', 'browseMyAddOn')
          .addToUi();
    }

Please help me

Upvotes: 0

Views: 2717

Answers (1)

Dayton Wang
Dayton Wang

Reputation: 2352

I think you should try this one instead:

function onInstall(e) {
   onOpen(e);
}

function onOpen(e) {
    SpreadsheetApp.getUi().createAddonMenu()
      .addItem('Browse My Add-on', 'browseMyAddOn')
      .addToUi();
}

Upvotes: 3

Related Questions