0
votes

I have a Google Apps Script that generates a new copy from a template spreadsheet.

However, the default setting of the new copy allows our domain to view it. I want to set its default permission via app script to RESTRICTED, equivalent to the UI shown below, so that I can only add specific editors or viewers.

sharing popup screenshot

I explored setDomainEdit() but the available examples online seem to apply to protected ranges and sheets. I'm not sure if that will address my requirement, but let me know.

Would someone kindly point me in the right direction?

1
You would want DriveApp and it's corresponding setSharing method for that. When you give permissions to a spreadsheet, it is treated like any other File - hence no sheet-specific API method. Also, please, do not add "thanks" part in the question, please - it somewhat frowned uponOleg Valter
Noted Oleg on your point about asking question. I tried your solution and it worked. There's just a specific point to note on the solution, which I posted as an answer in case others face the same. Thanks for the hint.TomR
Glad it worked for you. A curious behaviour you get - seems like a bug, placement of the call should not affect the result...Oleg Valter

1 Answers

1
votes

My problem is solved using this line:

newCopy.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.NONE);

One thing to note is to put this line at the end of the function, otherwise it does not seem to work at all. I got the idea from this related post.