Search code examples
google-apps-scriptmenu

Capture the name of the selected UI menu option


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.


Solution

  • 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');
     }