user2012403
user2012403

Reputation: 205

App Scripts spreadsheet error

Does anyone see a reason for an "Unexpected error" when deployed to Google App Scripts...something in doPost? Running the function produces no errors.

function doGet() { 
  var app = UiApp.createApplication(); 
  var form = app.createFormPanel(); 
  var flow = app.createFlowPanel(); 
  flow.add(app.createTextBox().setName("textBox")); 
  flow.add(app.createListBox().setName("listBox").addItem("option 1").addItem("option 2")); 
  flow.add(app.createSubmitButton("Submit")); 
  form.add(flow); 
  app.add(form); 
  return app; 
} 

function doPost(eventInfo) { 

  var app = UiApp.getActiveApplication();
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  ss.getRange("A1:A1");
  ss.getActiveRange().setValue("hello");  

  return app; 
}

Upvotes: 1

Views: 171

Answers (1)

Kalyan Reddy
Kalyan Reddy

Reputation: 1142

SpreadsheetApp.getActiveSpreadsheet() only works in Spreadsheet container bound scripts. Otherwise you need to use SpreadsheetApp.openById and specify the spreadsheet key to get.

When you "run the function" are you just running the doGet? If you select doPost in the dropdown and run it, you should see an error if this is not a Spreadsheet bound script.

Upvotes: 2

Related Questions