Reputation: 21
I am the Owner of a File / Folder and want to set the owner of the File and Folder through script to somebody else. It is part of a bigger code where I go through all subfolders and files of a given folder and want to give the ownership to somebody else. Problem is that the command 'setOwner()' does not work.
I have tried with the command folder.setOwner(Email Address) and it gave me the error message 'Invalid argument (line x, file "Code")' Dismiss '. Also I tried with the command folder.setOwner(User), got the same error message again.
var rootfolder = DriveApp.getFolderById(folderId);
rootfolder.setOwner("[email protected]"); //line x
or
var newOwner = DriveApp.getFileById(FileId).getOwner();
var rootfolder = DriveApp.getFolderById(folderId);
rootfolder.setOwner(newOwner); //line x
Note: 'FileId' is from a Public File
I also tried this Code, which worked. I got Email from Google Drive that the given folder was transfered from me to me.
var rootfolder = DriveApp.getFolderById(folderId);
rootfolder.setOwner(rootfolder.getOwner());
But I do not want to transfer it to myself, but to somebody else.
(I tried it on my personal and on my GSuite Account to a personal & GSuite account & all possibilities in between, nothing works)
Upvotes: 1
Views: 1134
Reputation: 21
I am dumb, the answer is super simple. I cannot share outside of my GSuite Account. If I try to transfer the Ownership to a user inside of your GSuite Account then it works perfectly!
The code is 100% correct.
Upvotes: 1