Code A and B do the same things but in case A when add a viewer, the command addViewer don't send the email to currentUser. Instead, in the case B when add a viewer the currentUser receive an email of file sharing.
//CASE A
var f = DocsList.getFolderById(folder.getId());
f.addViewer(currentUser);
//CASE B
var f = DriveApp.getFolderById(folder.getId());
f.addViewer(currentUser);
I would like to share wihouth automatic email because at the end of procedure I'll send a custom email (with the file inside folder link) if the procedure completed successfull, otherwaise I will delete the folder. How can I do? DocList will soon be deprecated!!
the method require "p" uppercase: Drive.Permissions.insert But after this little thing, the function returns an error:
I tried with this:
It works fine but only for FILE. For FOLDER (in fileId i put a folder ID) happens a strange thing:
Before run this code sharing Settings of folder are:
After running the code sharing Settings of folder become:
To do this you'll need to use the Drive API permissions.insert method [notice it's not DriveApp] to silently insert a permission.
The Drive API is exposed to Google Apps Script through the Google Drive Advanced Service. To use it you'll need to enable it for your project.
Once that's done your permission insert code might look like this:
I've edited this answer to include Laura's feedback below so it now works as expected.
If you are sharing a file with Google Scripts, the email notification will always go to the viewers and editors. The option to not send that email is only available if you share a file manually inside Google Drive.