Share a Drive document without notifying user with Google Apps Script

StuWatson picture StuWatson · Jan 17, 2014 · Viewed 7.6k times · Source

I am creating a workflow process in Apps Script where a Doc is generated from a template and shared with various users for approval. The Script sends a customised email notifying a user that the document requires their approval but they also receive a second email at each stage in the process from the user whose Drive the document is stored in saying "User has shared a document with you". Is there any way of disabling these alerts? When you share a document manually from your Drive, there is a checkbox option that allows you to choose whether or not the user receives a notification. However, I cannot find a way to disable this notification with Apps Script.

I am using doc.addEditors(users) to share the document.

Many Thanks

Answer

Rodrigo Chiong picture Rodrigo Chiong · Aug 14, 2014

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': '[email protected]'
   },
   fileId,
   {
     'sendNotificationEmails': 'false'
   });