Share a Drive document without notifying user with Google Apps Script

丶灬走出姿态 提交于 2019-11-28 08:26:51

There is a simple solution if you are working with Google Docs or Google SpreadSheets. You can use DocumentApp or SpreadSheetApp to share your Docs or SpreadSheets without email notification:

DocumentApp

var doc = DocumentApp.openById('124144')
doc.addEditor('example@mail.com').addViewer('example2@mail.com')

SpreadSheetApp

var spreadSheet = SpreadsheetApp.openById('124144')
spreadSheet.addEditor('example@mail.com').addViewer('example2@mail.com')

However, if you are working with documents that aren't Docs or SpreadSheets, you must share then using DriveApp and email notification will be send.

Another option would be to use the Drive advanced service (which you should enable in the Resources menu in the Script Editor).

The code used should be

Drive.Permissions.insert(
   {
     'role': 'writer',
     'type': 'user',
     'value': 'bob@example.com'
   },
   fileId,
   {
     'sendNotificationEmails': 'false'
   });

This isn't possible at the moment. More information about this topic can be found here: https://code.google.com/p/google-apps-script-issues/issues/detail?id=2829

A workaround suggested in the comments of the above issue is to use DocsList instead:

DocsList, SpreadsheetApp and DocumentApp have addEditor and addViewer methods that do not result in notification emails.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!