1
votes

My google sheets script is working well, but once it was published, the menu items are no longer there. So, instead of displaying the 'start' button in the addon (which works fine when it is run as a script) it only displays help for my addon. Does anyone have any ideas why this may be the case?

//Runs when the addon is installed 
function onInstall(e) {
  onOpen(e);
}

//Creates menu entry in google ui when opened 

function onOpen(e) {
  SpreadsheetApp.getUi().createAddonMenu()
      .addItem('Start', 'showSidebar')
      .addToUi();
}
1
Sometimes the menus doesn't show the add-on menu items and closing/open the spreadsheet / force tab refresh solves the problem - Rubén
I tried that and removing / downloading the addon, but its still doesn't work. I also looked at the console and didn't see any errors either. - Anant
If you are referring to the browser console, it will only show errors from client-side code. You should have to look to the Stackdriver logging/errors or to the Script Editor Execution Transcript. It's very likely that the problem is on another part of the add-on code. Is your add-on using global variables? - Rubén
I'm not using any global variables, and my addon is working fine as a script when I'm running it locally. Are there any other ways of creating the addon menu that is better for a published addon versus a script? - Anant

1 Answers

1
votes

Instead of

SpreadsheetApp.getUi().createAddonMenu()
    .addItem('Start', 'showSidebar')
    .addToUi();

try

var ui = SpreadsheetApp.getUi();
var menu = ui.createAddonMenu();
menu
    .addItem('Start', 'showSidebar')
    .addToUi();

The above because changes made about how authorizations scope are being handled on add-ons could make that chained statements like the one used on the question code doesn't work as expected and because the examples on https://developers.google.com/apps-script/guides/menus use more than one statement to create menus.