2
votes

In the past, DocsList service was used to manipulate files, but Google changed the way to handle files when presenting the DriveApp class in 2013, and since end of 2014, DocsList is deprecated. Most answers still refer to the use of DocsList, thats why I open this new question:

I create a new document and want to place it in a specific folder and access it for editing:

 // create a new document (and add x as editor)
  var newDoc = DocumentApp.create("name");
  newDoc.addEditor("x");
 // move file to right folder
  var file = DriveApp.getFileById(newDoc.getId());
  var folder = DriveApp.getFolderById(folderid);
  file.addToFolder(folder);

When requesting the file ID, this error message is thrown: "No item with the given ID could be found, or you do not have permission to access it"

How can I be able to create a file, but immediately after that, I don't have access to it?

1
Are you working from a shared file, and are not the owner? Or a script that has not been published yet by the owner? - Alan Wells
Yes, its a shared file and the script has not been published, but thats not the point. The error was in another part of my code - I'm sorry. I had acquired a wrong folder-id, so this was the object that couldn't be found. So, the above piece of code works. - Lilly

1 Answers

0
votes

Note that in the error message, it states:

or you do not have permission to access it

Don't assume that it's a problem with the code, or a bug in Apps Script. You may not have configured the permissions correctly. I've had this error message, when I edited a shared Apps Script, but the owner had not authorized certain new parts of the code. So, that's one way that you can create a file, and then not have access to it.