0

Well, I'm transferring a property of several files and I would like to omit the notification emails, I found some models right here in the library but I can not do it without my code, if someone can help me I'll be grateful

function folderTransfer()
  {
    var pas = DriveApp.getFolderById("ID");
    var arquivos = pas.getFiles();
    var me = 'email'; /* tirar este e-mail e deixar que seja qualquer prop.*/
    var novoProp = 'email';
  
    var pastas = pas.getFolders();
    while (pastas.hasNext())
    {
      var pasta = pastas.next();
      var pastaID = pasta.getId();
      fileTransfer(pastaID, me, novoProp);
      pasta.setOwner(novoProp);
      pasta.removeEditor(me);
    }
    //Transferir pasta pai para novoProp
    pas.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.VIEW);
    pas.setOwner('email');
    pas.removeEditor('email'); 
    
 function fileTransfer(pastaID, prop, novoProp)
  {
    var pasta = DriveApp.getFolderById('id');
    var arquivos = pasta.getFiles();
  
    while (arquivos.hasNext())
    {
      var arquivo = arquivos.next();
      arquivo.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.VIEW);
      arquivo.setOwner('email');
      arquivo.removeEditor('email');
     
      }
    }
 }
  • Duplicate of https://stackoverflow.com/questions/21189936/share-a-drive-document-without-notifying-user-with-google-apps-script – Brian Sep 21 '17 at 14:15
  • Unfortunately I do not know what I'm doing wrong, but this example does not work – Reydne Bruno Sep 21 '17 at 16:03

1 Answers1

0

You're opening the files with DriveApp, which forces the notification email (according to this related question). If you know what kind of file it is (doc, sheet, etc), you should open it with the appropriate app (SpreadsheetApp, DocumentApp, etc) to avoid sending a sharing notification. You would need to check the MIME type to share through the appropriate app.

Here is some untested code that might get closer:

while (arquivos.hasNext())
    {
      var arquivo = arquivos.next();
      var type = arquivo.getMimeType();
      if(type == "application/vnd.google-apps.document") {
        DocumentApp.openById(arquivo.getId()).addEditor('email');
      } else if(type == "application/vnd.google-apps.spreadsheet") {
        SpreadsheetApp.openById(arquivo.getId()).addEditor('email');
      } //etc...
    }

Note that you can only set the owner through DriveApp, which means you can not remove the email notification. This is the closest you can get through Apps Script.

More in GAS MIME types.

Brian
  • 4,274
  • 2
  • 27
  • 55