1
votes

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.

1
I think that when your script is put to the script editor of Spreadsheet and it shares the Spreadsheet with other user as the editor, when the user opens the Spreadsheet, the custom menu is created. So can I ask you about the detail flow for replicating your issue? By this, I would like to confirm it.Tanaike
@Tanaike I have an external library used by the menu script. That was the problem. And that library uses another 'library2'. So I have to share 1) the Sheet, 2) Library1, 3) Library2 with other users. This works, but is there a more efficient way I should be doing it?Womprat
Thank you for replying. If you can share the library, I think that to share it is suitable. If you don't want to share the library, if the script of library doesn't use the methods related to UI, how about running the script using Web Apps? By this, the script of library can be used without sharing it. But I'm not sure about the direction you expect. I apologize for this.Tanaike
Hi Womprat! Did you find anything useful regarding this?JustCurious

1 Answers

0
votes

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.