Hi guys,
We want to create a app script that will loop over all foles & files from a root folder id and change owner of folder/file if the owner is not the generic user that we want.
The root folder is a shared folder to our department (not a shared drives) as we wanted to have move flexibility. Employee will upload or move there documentation into that specific folder to share will all the informations and also in case of job leaving, we gonna keep documents.
I use a special generic account to create my script to avoid using my own account and i created the script code. I added some tests function just to confirm the concept, but i receive "Action Not allowed" on line that contain setOwner().
==================================================================
function testChangeOwnerOnOneFile() {
 var new_owner = 'XXXXXXXXXXXXXX';
 var fileId = "XXXXXXXXXXXXXXXXXX";
 var file = DriveApp.getFileById(fileId)
 var currentOwner = file.getOwner();
 Â
  if(DEBUG){
   Â
console.info("Current file owner is: %s",currentOwner.getEmail());
  }
 Â
  if(currentOwner.getEmail() != new_owner ){
   if(DEBUG){
   Â
console.info("Changing owner of current file from %s to %s",currentOwner.getEmail(),new_owner);
   }
   file.setOwner(new_owner);
  }
  else{
   if(DEBUG){
   Â
console.info("Current file owner is correct. Nothing to do!!!");
   }
  }
}
==================================================================
i replaced the id and email for security reason....
my appscript.json contain :
{
 "timeZone": "America/New_York",
 "dependencies": {
  "enabledAdvancedServices": [{
   "userSymbol": "Drive",
   "serviceId": "drive",
   "version": "v2"
  }]
 },
 "exceptionLogging": "STACKDRIVER",
 "runtimeVersion": "V8"
}
and also the file that i try to change the owner contain the account that run the script as EDITOR.
I'm assuming that i miss something, but didn't yet.
Any help ?