1
votes

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

2
It's not the same problem, set owner already works fine but it moves it into all items instead of My Drive, but I need the item to be in My Drive, and adding it to root or "my Drive" folders doesn't workmovac
Could there maybe be a way to specify which user's root folder you transfer a file to??movac
Or maybe there is a way to find the ID of a user's My Drive folder?movac

2 Answers

0
votes

So after a few days of driving myself INSANE and asking around literally everywhere I could think of we finally got word that this is an effect of the new Google Drive UI Rollout, so apparently right now it's just like THIS now, until google fixes it :C

WHAT AN UNSATISFYING ENDING.

0
votes

Unfortunately, it's not going to be possible exactly the way you describe.

As you've found, the file ownership can be changed. That's because you own the file and the file is accessible by Script through the authorization you granted to your Drive account.

Placing a file into a location on a different user's Drive is not possible because the script has no privilege to set a location on a Drive it knows nothing about.

However, it would be possible to set the location by running a script under each user account, but obviously that's a little arduous to setup and maintain.

One other option: If you use GAM (Google Apps Manager) it IS possible to make changes across accounts. This is because GAM is run under admin user access. Example from the GAM site:

This example updates the "My Ramblings" file to be starred and placed under a folder called "Brilliant things I've said" (assumes a folder by that name already exists for the user)

gam user [email protected] update drivefile drivefilename "My Ramblings" starred true parentname 'Brilliant things I've said'