4

Google finally shut of the Docslist class and my script stopped running this week. Here is what my code was.

  var folder = DocsList.getFolderById('XXXXXXXXX');
  var document = DocsList.getFileById(newSS.getId());
  document.addtoFolder(folder);

So I was trying to switch over the use DriveApp instead. So here is the code that I have switched to.

  var folder = DriveApp.getFolderById('XXXXXXXXXX');
  var document = DriveApp.getFileById(newSS.getId());
  document.addFile(folder);

I'm getting an error "TypeError: Cannot find function addFile in object". I think I'm using the addFile wrong, but I'm not exactly sure what I'm doing wrong. Any help?

Evan Morris
  • 113
  • 1
  • 5
  • possible duplicate of [How to update DocsList to DriveApp in my code](http://stackoverflow.com/questions/29777164/how-to-update-docslist-to-driveapp-in-my-code) – Zig Mandel Apr 22 '15 at 04:11

2 Answers2

5

Ok I figured it out. I had it backwards when using "addFile". I needed it to be

folder.addFile(document);

not

document.addFile(folder);
Evan Morris
  • 113
  • 1
  • 5
5

Not sure this will be helpful for others coming here, but I had to figure it out in my head that even though I had the file id stored in a variable I still had to getFileById(). Otherwise, my script would not know what file to add to the folder.

var newDoc = DocumentApp.create('Testing Team Drive MoveTo').getId();
var teamDrive = DriveApp.getFolderById('xxxxxxxxxxxxxxxxxx');
var file = DriveApp.getFileById(newDoc);
var moveFile = teamDrive.addFile(file);
Paul Murray
  • 95
  • 2
  • 9