1

I'm trying to add entries to the menu of a Google Sheet:

  ui.createMenu('Push to Sheet')
    .addItem('Texas', 'menuItem')
    .addItem('Illinois', 'menuItem')
    .addToUi();

In the callback function menuItem, is there any way to capture the name of the selected option (i.e. 'Texas' or 'Illinois')? If possible, this would serve as a marker to replace the inability to send parameters using the UI service.

tehhowch
  • 9,645
  • 4
  • 24
  • 42
user1592380
  • 34,265
  • 92
  • 284
  • 515
  • Possible duplicate of [Specify parameters for menu functions](https://stackoverflow.com/questions/25758181/specify-parameters-for-menu-functions) – tehhowch Aug 13 '18 at 17:27
  • Also related: https://stackoverflow.com/questions/19865377/how-can-i-know-which-menuitem-or-button-was-pressed https://stackoverflow.com/questions/17514412/adding-arguments-to-a-function-in-the-onopen-entries-object and https://stackoverflow.com/questions/50946493/how-to-know-which-menu-item-was-clicked – tehhowch Aug 13 '18 at 17:30

1 Answers1

4

No, this information is not exposed. You'll need to define specific functions to handle each menu item.

eg:

 function texasItem(){
    menuItem('Texas');
 }

 function illinoisItem(){
    menuItem('Illinois');
 }
Cameron Roberts
  • 7,127
  • 1
  • 20
  • 32