What is the difference between these two ways of getting the same thing (a new menu item)?

Version 1

 function onOpen(e) {
       .createMenu('My Menu')
       .addItem('My Menu Item', 'myFunction')
       .addSubMenu(SpreadsheetApp.getUi().createMenu('My Submenu')
           .addItem('One Submenu Item', 'mySecondFunction')
           .addItem('Another Submenu Item', 'myThirdFunction'))

Version 2

function onOpen() {
  var menu = [{name: "My Menu Item", functionName: "myFunction"}]
  SpreadsheetApp.getActiveSpreadsheet().addMenu("My Menu", menu);


This is a method of Spreadsheet class, i.e., it only applies to spreadsheets. All it does is add a new menu item with second-level submenus. On the upside, the syntax is very simple.


This method is currently available for three apps: SpreadsheetApp, DocumentApp, and FormApp. It returns an instance of user interface which can be used for more than just adding a menu item. One can show alerts, prompts, dialogs, and even add an interactive sidebar with custom content. Also, the menu creating options are richer: they allow separators and nested submenus. There are special add-on menus, too. Accordingly, the syntax is more verbose.


Neither of two methods is deprecated; use whichever fits your goal better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.