0
votes

I get this error when trying to execute this code from the script manager menu.

Error encountered: Script function not found: function click(e) { var app = UiApp.getActiveApplication(); app.getElementById('label').setVisible(false); SpreadsheetApp.getActiveSpreadsheet().show(ui); return app;
}

function readRows() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var values = rows.getValues();

  for (var i = 0; i <= numRows - 1; i++) {
    var row = values[i];
    Logger.log(row);
  }
};


function onOpen() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();   
  var entries = [{
    name : "ShowUi",
    functionName : "showSidebar"
  }];
  spreadsheet.addMenu("Script Center Menu", entries);
};

function click(e) {
   var app = UiApp.getActiveApplication();
   app.getElementById('label').setVisible(false);
  SpreadsheetApp.getActiveSpreadsheet().show(ui);
   return app;  
 }
function showSidebar(e){
  var ui= UiApp.createApplication()
     .setTitle('My UiApp Application')
     .setWidth(250)
     .setHeight(300);

  var button = ui.createButton("I am a button!");
  var handler = ui.createServerHandler(click);
  button.addClickHandler(handler);
  var label =ui.createLabel('The photograph on the dashboard taken years ago...').setId('label').setVisible(false);
  handler.addCallbackElement(label).addCallbackElement(button);
  ui.add(label);
  ui.add(button);

 SpreadsheetApp.getActiveSpreadsheet().show(ui);

  return ui;
};

I'm sorry that I had to post here for probably obvious but I could not find the answer anywhere else on the internet. Any solution or alternate way i could do the same thing would be greatly appreciated. thanks!

1

1 Answers

0
votes

Try something like this:

function showSidebar(e){

  var ui= UiApp.createApplication()
     .setTitle('My UiApp Application')
     .setWidth(250)
     .setHeight(300);

  var label = ui.createLabel('The photograph on the dashboard taken years ago...').setId('label').setVisible(false);

  ui.add(label);
  ui.add(ui.createButton('I am a button!', ui.createServerHandler('onClick')).setId('button'));


  SpreadsheetApp.getActiveSpreadsheet().show(ui);

  return ui;
};

function onClick(e) {
   var app = UiApp.getActiveApplication();
   app.getElementById('label').setVisible(false);
   //SpreadsheetApp.getActiveSpreadsheet().show(ui);
   app.close();
   return app;  
};