I am writing a script for my company that will automatically make a copy of a file in my own drive, then transfer ownership of the copy to a list of users from a spreadsheet. The script works completely except for that the file is created in the user's "All Files" and doesn't show up in their My Drive! Transferring ownership is not the problem I'm having, the problem is the location of the transferred file in the new owner's Drive.
I've tried sending it to their root folder but that didn't work, I'm not sure why? It sends it to My Drive for me, but it is copied into a folder that is already in My Drive for me (because I copy the file from a file that is in a folder in my drive already) but for anybody else on the list that the file is newly shared and transferred to, moving it to root does nothing and it remains in All Files without any labels on the file.
Does anybody have an idea how to move it automatically?
Here is the code that I've been using that works for my own My Drive but nobody else's on the list:
//Take new file out of parent folders
var folders = newDoc.getParents(); //get parents
for (var j = 0; i < folders.length; i++){ //loop through & delete parents
DocsList.getFileById(newDocId).removeFromFolder(folders[i]); //using DocsList
}
var root = DocsList.getRootFolder(); //Get root
DocsList.getFileById(newDocId).addToFolder(root); //add to my drive
edit: I was told that transferring ownership should automatically put it into the My Drive file but that isn't happening??
edit 2: I've tried using "addFile()" which SHOULD add it to My Drive folder in the user's folders, but it only adds it to the my drive of the person running the script and the rest of the users STILL get it only in their "All Items" folder. This is driving me nuts, someone please help ;C