【发布时间】:2013-12-11 10:56:23
【问题描述】:
我正在尝试使用具有动态复选框答案的 Google 表单和电子表格创建调查,这样如果参与者 1 在“其他”文本框中填写了答案,那么该答案将作为复选框提供给后续响应者.
我正在使用以下代码:
//a function to update Question 2's answer options
function updateChoices() {
//open the existing survey form
var form = FormApp.openById('1DEcjGr6x9KrlxapgIkFxreW1F-2Vlj_yDDzLQUhcmgk');
//retrieve existing Question 2
var items = form.getItems();
var question2 = items[1];
//retrieve previously submitted responses from response spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(ss.getSheets()[1]);
var numRows = ss.getLastRow()-1;
var values = SpreadsheetApp.getActiveSheet().getRange(2,16,numRows,16).getValues();
//declare a 1D array for existing survey answers
var answersSoFar = new Array(numRows);
//Pass the 2D array into the 1D array.
for (i=0; i < numRows; i++){
answersSoFar[i] = values[i][0];
}
//update the choices for the question
question2.setChoiceValues(answersSoFar);
}
我收到以下错误消息:
TypeError: Cannot find function setChoiceValues in object Item. (line 57, file "Code")
即使setChoiceValues 方法列在类项中(第 57 行是最后一行代码)。
我还尝试在 for 循环中使用 setChoices 和 createChoice 单独设置选项。
【问题讨论】:
标签: google-apps-script google-sheets google-forms