Menu

A custom menu in an instance of the user interface for a Google App. A script can only interact
with the UI for the current instance of an open document or form, and only if the script is [container-bound](https://developers.google.com/apps-script/scripts_containers) to the document or form. For more
information, see the [guide to menus](https://developers.google.com/apps-script/guides/menus).

```javascript
// Add a custom menu to the active spreadsheet, including a separator and a
// sub-menu.
function onOpen(e) {
  SpreadsheetApp.getUi()
      .createMenu('My Menu')
      .addItem('My Menu Item', 'myFunction')
      .addSeparator()
      .addSubMenu(
          SpreadsheetApp.getUi()
              .createMenu('My Submenu')
              .addItem('One Submenu Item', 'mySecondFunction')
              .addItem('Another Submenu Item', 'myThirdFunction'),
          )
      .addToUi();
}
```

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/base/menu#addItem(String,String)` | `https://developers.google.com/apps-script/reference/base/menu#` | Adds an item to the menu. |
| `https://developers.google.com/apps-script/reference/base/menu#addSeparator()` | `https://developers.google.com/apps-script/reference/base/menu#` | Adds a visual separator to the menu. |
| `https://developers.google.com/apps-script/reference/base/menu#addSubMenu(Menu)` | `https://developers.google.com/apps-script/reference/base/menu#` | Adds a sub-menu to the menu. |
| `https://developers.google.com/apps-script/reference/base/menu#addToUi()` | `void` | Inserts the menu into the instance of the editor's user interface. |

## Detailed documentation

### `addItem(caption, functionName)`

Adds an item to the menu. The label for a menu item should be in sentence case (only the first
word capitalized).

#### Parameters

| Name | Type | Description |
|---|---|---|
| `caption` | `String` | The label for the menu item, with only the first word capitalized. |
| `functionName` | `String` | The name of the function to invoke when the user selects the item. You can use functions from included libraries, such as `Library.libFunction1`. |

#### Return


`https://developers.google.com/apps-script/reference/base/menu#` --- This `https://developers.google.com/apps-script/reference/base/menu#`, for chaining.

*** ** * ** ***

### `addSeparator()`

Adds a visual separator to the menu.

#### Return


`https://developers.google.com/apps-script/reference/base/menu#` --- This `https://developers.google.com/apps-script/reference/base/menu#`, for chaining.

*** ** * ** ***

### `addSubMenu(menu)`

Adds a sub-menu to the menu.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `menu` | `https://developers.google.com/apps-script/reference/base/menu#` | The sub-menu, constructed like a top-level menu. |

#### Return


`https://developers.google.com/apps-script/reference/base/menu#` --- This `https://developers.google.com/apps-script/reference/base/menu#`, for chaining.

*** ** * ** ***

### `addToUi()`

Inserts the menu into the instance of the editor's user interface.