Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript FormApp.openById()-找不到具有给定ID的项_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript FormApp.openById()-找不到具有给定ID的项

Javascript FormApp.openById()-找不到具有给定ID的项,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我有一个GoogleSheets触发器功能,它可以在表单提交中根据为我的一个问题选择的值将提交内容放置在表单中。我正在尝试使用“作为附加项进行测试”功能测试我的函数,但是当我提交表单时,我在我的onSubmit函数中收到一个错误,错误消息是找不到具有给定ID的项,或者您没有访问它的权限。(第9行,文件“代码”)来自触发器formSubmit 这是错误的一行 var form = FormApp.openById(ss.getFormUrl()); 这使我认为存在身份验证问题,但我不确定如何

我有一个GoogleSheets触发器功能,它可以在表单提交中根据为我的一个问题选择的值将提交内容放置在表单中。我正在尝试使用“作为附加项进行测试”功能测试我的函数,但是当我提交表单时,我在我的
onSubmit
函数中收到一个错误,错误消息是
找不到具有给定ID的项,或者您没有访问它的权限。(第9行,文件“代码”)来自触发器formSubmit

这是错误的一行

  var form = FormApp.openById(ss.getFormUrl());
这使我认为存在身份验证问题,但我不确定如何进一步调试

完整代码:

function onSubmit(e) {
  //Open Marketing - Discoveries and Changes - v1
  var sheet = e.range.getSheet();

  //Return Spreadsheet that contains this sheet
  var ss = sheet.getParent();

  //Open Marketing - Discoveries and Changes - v1
  var form = FormApp.openById(ss.getFormUrl());

  //Destination sheet based on "Location of Change"
  var destSheet = getSheet(ss, e.namedValue['Location of Change']);

  //Store response in destination sheet
  destSheet.appendRow(e.values);

  function getSheet( spreadsheet, sheetName, headings) {
    spreadsheet = SpreadsheetApp.getActive();
    var sheet = spreadsheet.getSheetByName(sheetName);
    if (sheet == null) {
      sheet = spreadsheet.insertSheet(sheetName);
      if (headings && headings.constructor === Array) {
        sheet.getRange(1,1,1, headings.length).setValues([headings]);
      }
    }
    return sheet;
  }

}

openById()
ss.getFormUrl()
的组合不正确。在对的回答中,使用了
openByUrl()

var form = FormApp.openByUrl(ss.getFormUrl());

如果要使用
openById()
,则需要从URL中提取ID。(请参阅。)

捕捉得好!我做了更改,不再出现错误,但是
namedValue
似乎未定义。这是否表示表单或表单信息存在问题<代码>类型错误:无法从未定义中读取属性“更改位置”。(第16行,文件“Code”)可能是因为我的触发器功能不能与作为附加功能的测试一起使用吗?我知道它在脚本编辑器中不起作用,但在使用
Test作为附加组件时,我不认为这是一个问题
如何安装触发器?(必须以编程方式)我通过UI“所有触发器”按钮添加了触发器。这在测试中不起作用?测试时不支持读取、可安装的触发器。依赖于可安装触发器的功能将不可测试。您仍然可以在绑定脚本中测试触发器。