Google apps script 谷歌表单应用程序脚本;获取表单响应数据时遇到问题

Google apps script 谷歌表单应用程序脚本;获取表单响应数据时遇到问题,google-apps-script,Google Apps Script,我想我遇到了一个错误?我在谷歌表单中有一个脚本,它将获取提交的谷歌表单值,并将它们放入谷歌文档表中 我已经将我的代码迁移到谷歌表单上,提交时它似乎没有抓取我输入的数据 function doTheWork(e) { var timeStamp = String(e.values[0]); var entryEmail = String(e.values[1]); var name = String(e.values[2]); var number = String(e.v

我想我遇到了一个错误?我在谷歌表单中有一个脚本,它将获取提交的谷歌表单值,并将它们放入谷歌文档表中

我已经将我的代码迁移到谷歌表单上,提交时它似乎没有抓取我输入的数据

function doTheWork(e) {  
  var timeStamp = String(e.values[0]);  
  var entryEmail = String(e.values[1]);
  var name = String(e.values[2]);
  var number = String(e.values[3]);

  var cells = [timeStamp, entryEmail, name, number];
};
作为调试过程的一部分,由于以下代码,我发现这就是错误:

var name = 'Bob';
var number = '20';
var cells = [name, number];

基本上,手动添加字符串是有效的。但是我需要它从表单中获取数据。

我回答这些问题是因为虽然上面评论中的链接让我走上正轨,但我确实花了一段时间才理解文档的含义

解决方案如下:

// Get the for - You could alternatively open by id.
var form = FormApp.getActiveForm();

// Get responses
var formResponses = form.getResponses();

// Loop through the filled out form to gather all of the responses
for (var i = 0; i < formResponses.length; i++) {
  // Prepare the array
  var formResponse = formResponses[i];
  // Just FYI I got the response URL because it was handy for my situation. It is not necessary code but I if anyone else gets stuck the way I did, hopefully this helps
  var editUrl = String(formResponse.getEditResponseUrl());
  var itemResponses = formResponse.getItemResponses();
  // My form had two fields for this test. Name & Number. Here is how I was able to access the answers.
  var name = itemResponses[0].getResponse();
  var number = itemResponses[1].getResponse();
}
//获取for-您也可以通过id打开。
var form=FormApp.getActiveForm();
//得到回应
var formResponses=form.getResponses();
//在填写好的表单中循环以收集所有响应
对于(var i=0;i
vs@tehowch那么我的函数已经在表单提交中了,我是否需要一个充当自定义触发器的辅助函数来调用这些项?那么在我的第二个函数中如何调用它们呢。我还可以使用“e.values”吗?表格中没有e.values。e、 值仅在电子表格中可用。所以问题仍然存在,您是在表单脚本编辑器中还是在电子表格脚本编辑器中。请仔细阅读@tehhowch提供的链接。表单脚本编辑器。正在读取当前链接并尝试解析。把事情弄清楚真是太好了。