title: How I create a SubMenu whit google script
body: <p>I need to know how create a simple menu with 2 menu items(<strong>A</strong> and <strong>B</strong>): the first one(A) contains 1 item (<strong>A1</strong>),the second one(B), contains 3 items inside(<strong>B1,B2,B3</strong>)</p>
  
  <p>I can create an example but always fail:</p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>      var handler = app.createServerHandler();
       //Create menu bar
        var menuBar = app.createMenuBar(true);
  
        var data =  ss.getSheets()[LOG_SHEET_INDEX].getDataRange().getValues();
  
        var lastRow = ss.getLastRow();
        for(var row = 1; row &lt; lastRow; row++){
          var id_menu =1;
          if(data[row][0]==0){
            var nivel = data[row][1];
            var menuItem = app.createMenuItem(data[row][2], handler);
  
            var separator = app.createMenuItemSeparator();
            menuBar.addSeparator(separator);
            var subMenu = app.createMenuBar(true).setId("subMenu"+nivel);
            for(var i = 1; i&lt; lastRow; i++){
              if(data[i][0]==nivel){
                var sm = app.getElementById("subMenu"+nivel)
                this[sm.addItem(data[row][2], handler)];
              }
  
            }menuItem.setSubMenu(sm);
  
          }menuBar.addItem(data[row][2], app.createMenuBar(true));
  
        }
  
  
        app.add(menuBar);
  </code></pre>
  
  <p><strong>RESULT</strong></p>
  
  <p><img src="https://i.stack.imgur.com/uYNlW.png" alt="fail"></p>
  
  <p>and i need something like (hidding A1,B1,B2,B3 : showing when focus A|B):</p>
  
  <pre><code>    ____
      A
          A1
      ____
      B
          B1
          B2
          B3
  </code></pre>
  
  <p><strong>THIS IS MY SPREAD:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/q8qrj.png" alt="fail2"></p>
  
  <p>Please Help!!</p>