Google Script var获取未定义的值

时间:2012-08-20 13:33:00

标签: javascript google-apps-script

我的Google Script代码存在问题:

当我这样做时:var Emails = e.parameter.Email; (在功能Aut_User中)

我无法得到该值,它似乎未定义,值未从一个函数传递到另一个函数。

有什么问题?

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 个答案:

答案 0 :(得分:1)

您的代码中有错误:

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

这里的第二行应该是:

Contactpassword.setName('Password');

我通过在Aut_User(e)中使用以下代码找到了这个:

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

然后将'输出'发送到我可以阅读的地方。我看到'密码'的值是输入的电子邮件地址。