Google apps script 更改文本框中的文本时出错

Google apps script 更改文本框中的文本时出错,google-apps-script,Google Apps Script,我创建了一个简单的UI,只有几个文本框和几个按钮。这个概念基本上是我维护的电子表格的投票应用程序。当脚本运行时,它会将电子表格的每一行显示在文本框中,并允许用户对该项目进行投票。我手工创建了UI: function BuildUI() { var app = UiApp.createApplication().setTitle("Voting Machine").setWidth(700); var doc = SpreadsheetApp.getActiveSpreadsheet(); var

我创建了一个简单的UI,只有几个文本框和几个按钮。这个概念基本上是我维护的电子表格的投票应用程序。当脚本运行时,它会将电子表格的每一行显示在文本框中,并允许用户对该项目进行投票。我手工创建了UI:

function BuildUI() {
var app = UiApp.createApplication().setTitle("Voting Machine").setWidth(700);
var doc = SpreadsheetApp.getActiveSpreadsheet();
var buttonWidth = "125px";

// Panels
var mainPanel = app.createVerticalPanel();
var horzPanel = app.createHorizontalPanel();
var buttonGrid = app.createGrid(1,3);

// Textboxes
var txtCat = app.createTextBox().setName("txtCat").setId("txtCat");
var txtIdea = app.createTextBox().setName("txtIdea").setId("txtIdea");

// Handlers
var handler = app.createServerHandler();
handler.setCallbackFunction("recordVote");
handler.addCallbackElement(txtCat).addCallbackElement(txtIdea);

// Buttons
var voteNo = app.createButton("No").setId("voteNo")
  .addClickHandler(handler).setWidth(buttonWidth);
var voteMaybe = app.createButton("Maybe").setId("voteMaybe")
  .addClickHandler(handler).setWidth(buttonWidth);
var voteYes = app.createButton("Yes").setId("voteYes")
  .addClickHandler(handler).setWidth(buttonWidth);

horzPanel.add(txtCat).add(txtIdea)
buttonGrid.setWidget(0, 0, voteNo)
  .setWidget(0, 1, voteMaybe)
  .setWidget(0, 2, voteYes);
mainPanel.add(horzPanel).add(buttonGrid);

app.add(mainPanel);
doc.add(app);
}
问题是,当我调用我的NextIdea函数时,我得到一个错误:

function NextIdea() {
var app = UiApp.getActiveApplication();
... Get the next row of the spreadsheet ...
app.getElementById("txtCat").setText("TestValue"); // <--- This is the error line
这是我第一次尝试制造气体,不确定我错过了什么。我确实看到很多使用
return应用程序的例子在函数末尾,但我的印象是,只有当脚本作为服务发布时才使用它。我试图在电子表格中使用它(使用
onOpen
而不是
onGet
等)

在本部分:

function NextIdea() {
var app = UiApp.getActiveApplication();
... Get the next row of the spreadsheet ...
app.getElementById("txtCat").setText(nextRowCat) // <--- This is the error line
函数NextIdea(){
var app=UiApp.getActiveApplication();
…获取电子表格的下一行。。。

app.getElementById(“txtCat”).setText(nextRowCat)//很抱歉,我意识到当我中断下一行的处理时,你看不到该变量的定义位置。我将编辑该问题以使其更清楚。但是,它是一个已分配的变量(我可以验证它是否具有在调试视图中应该具有的值)问题是我试图在我的实时代码中使用
.setText=“TestValue”
,当我在这里创建示例时(我主要是为了缩短代码),我使用了
.setText(“TestValue”)
,正如预期的那样。
function NextIdea() {
var app = UiApp.getActiveApplication();
... Get the next row of the spreadsheet ...
app.getElementById("txtCat").setText(nextRowCat) // <--- This is the error line