Search code examples
javascriptgoogle-apps-scriptgoogle-apigoogle-drive-apigoogle-apps

Share a Drive document without notifying user with Google Apps Script


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


Solution

  • 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('[email protected]').addViewer('[email protected]')
    

    SpreadSheetApp

    var spreadSheet = SpreadsheetApp.openById('124144')
    spreadSheet.addEditor('[email protected]').addViewer('[email protected]')
    

    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.