简体   繁体   中英

Function triggered onOpen stopped working

Some time ago I wrote a script for one of my spreadsheets, that uses installable trigger onOpen to initiate SpreadsheetApp.getUi function.

The function looks like that:

function addMenu()
{
  // adding custom menu 
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('New menu')
  .addSubMenu(ui.createMenu('menu')                  
              .addItem('item', 'functionName')
              .addSubMenu(ui.createMenu('additive')
                          .addItem('subitem', 'subfunctionName')))
  .addToUi();
};

This menu worked like a charm using installable trigger onOpen being fired from spreadsheet. The functions called by these menu items use UserProperties, so I made sure this is not running anonymously.

This week I noticed that the menu no longer works when I open the spreadsheet - it only works if I call it directly from the script editor.

I have no idea how to fix this - I made no changes to the script, and checked to be sure nobody else did meddle with it. It's the same script that worked up until now.

I would very much appreciate the help on this one, it's puzzling to say the least.

Thanks!

Are the submenus supposed to be nested inside each other? If not, you're probably looking for:

function addMenu() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('New menu')
    .addSubMenu(ui.createMenu('menu')                  
      .addItem('item', 'functionName')
    )
    .addSubMenu(ui.createMenu('additive')
      .addItem('subitem', 'subfunctionName')
    )
    .addToUi()
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM