Reputation: 153
I have some basic custom menus I create in my Google Apps Script Editor:
// Script has a library added under Resources -> Libraries -> [library1]
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('MyMenu').addItem('Refresh Data', 'refresh_the_data').addToUi();
}
function refresh_the_data(){
library1.refresh();
}
The menu appears for me (the developer) but doesn't appear when I share the Sheet with other users.
The onOpen() function uses an external library in the 'refresh_the_data' function. When running onOpen() as a different user, I get the error 'You do not have access to library library1, used by your script, or it has been deleted.'
So I can share 'library1' with all users who need access to this script. Is there a better way to share script functionality with an Add-on or an App? Ideally I would like to keep the library private (not expose the full code of the library) although I understand I have to expose the code if I want other users to use the functionality.
Upvotes: 2
Views: 2676
Reputation: 2930
Only enumerable global properties are visible to the library users if you grant them view level access. Moreover, you can select what methods should not be visible/usable to your users by ending their name with an underscore (for example myFunction_()
). For more information regarding how to set to private certain methods and variables check out the documentation's best practises.
Furthermore, you can also adjust the resource scoping between library A and B and between library A and your script. In this way you can have a resource shared between A and B where A uses it without having to grant your users read level access to library B.
Upvotes: 1