Nick Dorogavtsev
Nick Dorogavtsev

Reputation: 13

Saving data from GUI back to Google Spread Sheet

Trying to save data from active UI build in GUI back to spreadsheet. But cannot figure out how to retrive string value from text box in the UI. This is what I'm trying to do:

function saveChanges() {  
  var Text;
  var Location;
  var app = UiApp.getActiveApplication();

  Text = app.getElementById('CompanyLegalNameTextBox').getText();
  Location = "C3";
  SpreadsheetApp.getActiveSheet().getRange('Location').setValue('Text');  
}

Getting error: TypeError: Cannot find function getText in object Generic.

Thank you si much for your help in advance!

Upvotes: 0

Views: 149

Answers (2)

Arun Nagarajan
Arun Nagarajan

Reputation: 5645

The specific details you care for in the are the fact that getElementById returns a GenericWidget which doesn't support any get operations.

Another confusing aspect is Id and Name. Params into callback functions are passed in using name and getElementById uses Id (as the name implies). For simplicity, I usually set the Name and the Id of my widgets both at the same time to the same thing. Then you are able to pass a reference to your widget by adding it to the call back via the addCallbackElement

   ///snippet
   var textBox = app.createTextBox()
                   .setId('CompanyLegalNameTextBox')
                   .setName('CompanyLegalNameTextBox');

  app.add(textBox);
  var handler = app.createServerHandler('saveChanges');
  handler.addCallbackElement(textBox);
  button.addClickHandler(handler); //button defined elsewhere

And your call back code looks like this - notice the "e" parameter

  function saveChanges(e) {  
    var textValue = e.parameter.CompanyLegalNameTextBox;
    ///snippet 
  }

Upvotes: 1

Serge insas
Serge insas

Reputation: 46802

This is clearly explained in details in the UI App documentation, please read it before asking.

Upvotes: 0

Related Questions