我在附加到Google表单的Apps脚本功能中发生了一个奇怪的错误。
我调用响应,然后将它们列在数组中。日志显示数组中有6个项目,它们匹配六个表单问题:
[18-05-08 00:13:31:900 AEST] [ItemResponse, ItemResponse, ItemResponse, ItemResponse, ItemResponse, ItemResponse]
当我打电话给前两个时,它运作得很好。还有其他问题,并说出undefined
。
// Open a form by ID and log the responses to each question.
var form = FormApp.getActiveForm();
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++) {
var formResponse = formResponses[i];
var editUrl = String(formResponse.getEditResponseUrl());
var theResponseId = formResponses.indexOf(form);
var itemResponses = formResponse.getItemResponses();
var timestamp = formResponse.getTimestamp();
var firstName = itemResponses[0].getResponse();
var lastName = itemResponses[1].getResponse();
Logger.log(itemResponses); // Log shows there are 6 objects in the array. Matching the amount of Form Questions.
// If I try to use these variables below, it doesn't work and the script 'breaks' at this point.
//var number = itemResponses[2].getResponse();
//var email = itemResponses[3].getResponse();
//var firstName2 = itemResponses[4].getResponse();
//var comments = itemResponses[5].getResponse();
}
注意:我已尝试FormApp.openById('id');
查看是否可能获得活动表单是个问题。这没有用。
答案 0 :(得分:1)
这是因为有些答案提交了2个问题表格。如果您在更新表单之前提交了一些回复,那么这些新问题的答案将是“未定义的”。