Mr. Dominic
Mr. Dominic

Reputation: 69

Dropdown list with error

I have this UiApp that presents the user with two different options in a dropdown list. User has two options when they select one of them another uiapp comes and displays some information, and it has a button to go back to original Menu. The problem I am having is that when I make the choices I get an error that says "Error Encountered: An unexpected error occurred." and the same happens when I click the go back button on the option 1 and 2. Is this a bug of GAS, or is it code that shouldnt be there?

Thank you!

 function Menu(e) {
  var app = UiApp.createApplication().setTitle(" Title"); 
  var dropDownList = app.createListBox().setName('list').setId('list');
  var infoLabel = app.createLabel('Scroll around to select the service     desired').setId('infoLabel');
//addItems  
  dropDownList.addItem("Options");
  dropDownList.addItem("Option1");
  dropDownList.addItem("Option2");

  var handler = app.createServerClickHandler('changeMe');
  handler.addCallbackElement(dropDownList);  
  dropDownList.addChangeHandler(handler);
  app.add(dropDownList);
  app.add(infoLabel);
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  spreadsheet.show(app);
  return app;
  }

  function changeMe(e) {
      if(e.parameter.list === 'Option1'){
        var app1 = UiApp.createApplication();
        var html1 = app1.add(app1.createHTML("<p><i>Hello you have selected Option  1</i>    </p>")).setHeight(800).setWidth(600);
        var button1 = app1.createButton('Go back').setId("button1");
        app1.add(button1);
        var handler2 = app1.createServerHandler('Menu');
        button1.addClickHandler(handler2); 
        var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
        spreadsheet.show(app1);
        return app1;
        }

  else if (e.parameter.list === 'Option2'){;
     var app2 = UiApp.createApplication();
     var html2 = app2.add(app2.createHTML("Hello You have selected Option2"));
     var button2 = app2.createButton('Go back').setId("button");
     app2.add(button2);
     var handler2 = app2.createServerHandler('Menu');
     button2.addClickHandler(handler2);                                                                  
     var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
     spreadsheet.show(app2);
     return app2;
     }
   }

Upvotes: 0

Views: 277

Answers (1)

Kalyan Reddy
Kalyan Reddy

Reputation: 1142

Try removing the 3 "return app" lines. This seems to work for me. The show method will automatically put it on the spreadsheet.

Upvotes: 1

Related Questions