执行失败:TypeError: - 用DriveApp替换DocsList

时间:2015-04-23 12:24:21

标签: javascript google-apps-script google-apps google-docs-api

我现在明白,由于最近DocsList的贬值,我的故障脚本开始了。按照说明,我现在已将此实例替换为DriveApp。但是,执行仍然失败,正在各种文件夹中创建多个文件副本,并且电子邮件不会发送。我真的很感激有人可以帮助我解决这个问题,因为这会杀死我的新手大脑!

这是执行记录。

[15-04-23 12:57:06:192 BST] FormApp.getActiveForm() [0.234 seconds]
[15-04-23 12:57:06:491 BST] FormApp.getActiveForm() [0.23 seconds]
[15-04-23 12:57:06:524 BST] Starting execution
[15-04-23 12:57:06:558 BST] FormResponse.getItemResponses() [0.012 seconds]
[15-04-23 12:57:06:559 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:06:559 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:06:559 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:06:890 BST] SpreadsheetApp.openById([1pxcz1Xt9_29n2L5kDgJlacHCZ8APlIXiTsPXL5M1zuM]) [0.33 seconds]
[15-04-23 12:57:07:178 BST] Spreadsheet.getDataRange() [0.286 seconds]
[15-04-23 12:57:07:269 BST] Range.getValues() [0.09 seconds]
[15-04-23 12:57:07:270 BST] Range.getLastRow() [0 seconds]
[15-04-23 12:57:07:270 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:07:271 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:07:271 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:07:271 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:07:271 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:07:271 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:07:272 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:07:272 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:07:272 BST] (class).getResponse() [0 seconds]
[15-04-23 12:57:07:513 BST] SpreadsheetApp.openById([1fdOI61__16jFCEDJCvWHtVMu6BhkxS88x5408-JB8oA]) [0.239 seconds]
[15-04-23 12:57:07:513 BST] Spreadsheet.getSheetByName([main]) [0 seconds]
[15-04-23 12:57:07:690 BST] Sheet.getLastRow() [0.176 seconds]
[15-04-23 12:57:07:691 BST] Sheet.getRange([475, 1, 1, 7]) [0 seconds]
[15-04-23 12:57:07:693 BST] Range.setValues([[[23.04.2015 12:57:07, Andrew Davies, Lisa Smith, AWOL, 2015-04-23, 11:30, 20:00]]]) [0.001 seconds]
[15-04-23 12:57:07:859 BST] CalendarApp.getDefaultCalendar() [0.165 seconds]
[15-04-23 12:57:08:275 BST] Calendar.createEvent([Lisa Smith  AWOL deadline., Thu Apr 23 07:00:00 PDT 2015, Thu Apr 23 07:15:00 PDT 2015, {guests=andrew.davies@uk.webhelp.com,adam.taylor@uk.webhelp.com, sendInvites=true}]) [0.414 seconds]
[15-04-23 12:57:08:485 BST] DriveApp.getFileById([17i-HIzzNTMeVs8u7gIs_NHDoCDlFWX2y7D6LjnYEjUI]) [0.208 seconds]
[15-04-23 12:57:11:188 BST] File.makeCopy([AWOL_copy]) [2.702 seconds]
[15-04-23 12:57:11:280 BST] Execution failed: TypeError: Cannot find function removeFromFolder in object AWOL_copy. (line 164, file "utils") [4.646 seconds total runtime]

这是引用的错误代码

function copy_file(path, file,new_name) {
  var file_copy = file.makeCopy(new_name);
      file_copy.removeFromFolder(DriveApp.getRootFolder());
      file_copy.addToFolder(DriveApp.getFolder(path));
  return file_copy;
}


function create_doc_in_path(path, filename) {
  var doc = DocumentApp.create(filename);
  var file = DriveApp.getFileById(doc.getId());
  file.removeFromFolder(DriveApp.getRootFolder());
  file.addToFolder(DriveApp.getFolder(path));
  return doc;
}

1 个答案:

答案 0 :(得分:0)

Zig Mandel是正确的,您需要使用较新的api映射旧api的每个功能。more info of DriveApp

这里的代码可能有用。

function copy_file(path,file,new_name) 
{
  var folder = DriveApp.getFolderById(path);
  var file_copy = file.makeCopy(new_name);
  var document = DriveApp.getFileById(file_copy.getId());
  folder.addFile(document);
  return file_copy;
}

function create_doc_in_path(path,filename) 
{
  var folder = DriveApp.getFolderById(path);
  var doc = DocumentApp.create(filename);
  var file = DriveApp.getFileById(doc.getId());
  folder.addFile(file);
  return doc;
}