0

I am having some problem with my code for Google Script below:

When I do: var Emails = e.parameter.Email; (IN FUNCTION Aut_User)

I cant get the value, it appears undefined, value is not passing from one function to another.

What is wrong?

function doGet() {
  var app = UiApp.createApplication();
  var grid = app.createGrid(3, 2);
  grid.setWidget(0, 0, app.createLabel('Informações para Login:'));

  var Contactemail = app.createTextBox();
  Contactemail.setName('Email'); 
  grid.setWidget(1, 0, app.createLabel('Email:'));
  grid.setWidget(1, 1, Contactemail);

  var Contactpassword = app.createPasswordTextBox();
  Contactemail.setName('Password'); 
  grid.setWidget(2, 0, app.createLabel('Senha:'));
  grid.setWidget(2, 1, Contactpassword);


  var panel = app.createVerticalPanel();
  panel.add(grid);


  var button = app.createButton('Logar');
  var handler = app.createServerHandler('Aut_User'); 
  handler.addCallbackElement(grid);
  button.addClickHandler(handler);

  panel.add(button);
  app.add(panel);
  return app;
}

function getColIndexByNamelink(colName, ID) {
  var sheet = SpreadsheetApp.openById(ID).getSheets()[0];
  var numColumns = sheet.getLastColumn();
  var row = sheet.getRange(1, 1, 1, numColumns).getValues();
  for (i in row[0]) {
    var name = row[0][i];
    if (name == colName) {
      return parseInt(i) + 1;
    }
  }
  return -1;
}

function Aut_User(e) {
  var ID = "0AqmZV_vU4x5cdFQyOFo2TlE3dkxFYi1rVUk3OUxzYWc";
  var sheet = SpreadsheetApp.openById(ID).getSheets()[0];
  var lastRow = sheet.getLastRow();
  var Emails = e.parameter.Email;  //PROBLEM HERE
  //parametros da outra funcao
  for (var i = 2; i < (lastRow + 1); i++) {
    sheet.getRange("A4").setValue(Emails);
    //conferir os dados
  }
}

1 Answer 1

1

You have a mistake in your code:

var Contactpassword = app.createPasswordTextBox();
Contactemail.setName('Password');

The second line here should be:

Contactpassword.setName('Password');

I found this by using the following code in Aut_User(e):

var app = UiApp.getActiveApplication();
var output = '';
for (var i in e.parameter) {
   output += i + ' = ' + e.parameter[i] + '; ';
}

Then sending 'output' to a place I could read it. I saw the value for 'Password' was the email address entered.

Sign up to request clarification or add additional context in comments.

4 Comments

there is indeed a double name assignation and, quite logically, the last one has priority ;-) +1 for Weehooey's method, straightforward and efficient !
Thank you, I have a question: how do I show a link on the screen is that this script runs as a gadget?
@RenanOtero I do not understand your question. You might want to start another question and ask with more detail.
Are you looking for the anchor widget?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.