如何使用 Google Apps 脚本检索用户在 Google 表单中为其他字段输入的值?

How to use Google Apps Script retrieve the value a user typed in for an Other field in Google Forms?

我有一个 Google 表单,它是一个带有 "Other" 选项的简单复选框列表。作为表单的作者,它看起来像这样:

当我填写表格时,我可以选中 "Other" 复选框并输入一个值,然后提交。

但是当我的 Google Apps 脚本运行时,

  var choices = checkboxItem.getChoices();
  Logger.log("Choices array length: %s", choices.length);

  var results = [];
  for (var i = 0; i < choices.length; ++i) {
    results.push(choices[i].getValue());
  }

  Logger.log("getFormChoicesAsStrings %s", JSON.stringify(results));

它没有看到我输入的 "Other" 值(在本例中:"Steve Jobs"),日志输出证明了这一点:

[19-01-12 20:31:59:164 PST] Logger.log([Choices array length: %s, [1.0]]) [0 seconds]
[19-01-12 20:31:59:165 PST] Logger.log([getFormChoicesAsStrings %s, [["John Doe"]]]) [0 seconds]

API for CheckboxItem allows a true/false whether or not an Other option is displayed, and the API for Choice 没有提供其他选项的任何内容。

我可以调用什么 API 来读取其他选项的值?

  • 用户选中复选框并将值设置为 "Other",然后单击提交按钮。
  • 在上述情况下,您想要检索包含 "Other" 部分的值的响应值。

如果我的理解是正确的,这个修改怎么样?

修改点:

  • 在你的脚本中,虽然我看不到整个脚本,但我认为从表单中检索到的项目。这不是响应值。

修改后的脚本:

请复制并粘贴以下脚本并为 myFunction() 安装触发器。

// FormApp.getActiveForm() // This is used for adding a scope of https://www.googleapis.com/auth/forms
function myFunction(obj) {
  var r = obj.response.getItemResponses();
  r.forEach(function(e) {
    var r1 = e.getItem().getTitle();
    var r2 = e.getResponse();
    Logger.log(r1); // "Who attended?"
    Logger.log(r2); // ["John Doe","Steve Jobs"]
  });
}

注:

  • 当您使用此脚本时,请安装 myFunction() 作为可安装触发器。
    • "Choose which function to run" 是 "myFunction".
    • "Select event source" 是 "From form".
    • "Select event type" 是 "On form sumit".

参考文献:

如果我误解了你的问题,请告诉我。我想修改一下。