I will distribute the spreadsheet with the onOpen menu among several users. I would like to keep the definitions and functionality of the menu in the library, so if I add some menu options or update some functions, everyone using this spreadsheet will automatically update.
So far in the spreadsheet script, I only had this simple code:
function onOpen() { myLib.loadMenu(); }
The menu is loaded into the spreadsheet without problems, however, no matter what I called the menu call and the actual function (with or without myLib.), I always get the error message โScript function doSomething could not be foundโ when using the option from this menu .
Any idea on what I should call the function call in the menu and the actual function in the library for this approach to work.
Thanks Fausto
EDIT-1 . Let me give more details and sample code.
My goal is to add additional options to this menu from the library without updating each user table.
This is the sample code included in the script table, the library has not yet been used, and it works without problems.
function onOpen() { testMenu(); } function testMenu() { SpreadsheetApp.getActiveSpreadsheet().addMenu( 'Testing', [ { name: 'Do Something #1', functionName: 'someFunction1' }, null, { name: 'Do Something #2', functionName: 'someFunction2' } ]); } function someFunction1() { SpreadsheetApp.getActiveSheet().getRange("A1").setValue("Hello from someFunction1"); } function someFunction2() { SpreadsheetApp.getActiveSheet().getRange("A2").setValue("Bye from someFunction2"); }
I want to do the same, but split the code between the script table and the library, as follows
In a spreadsheet script
function onOpen() { xsLib.testMenu(); }
In library
function testMenu() { SpreadsheetApp.getActiveSpreadsheet().addMenu( 'Testing', [ { name: 'Do Something #1', functionName: 'someFunction1' }, null, { name: 'Do Something #2', functionName: 'someFunction2' } ]); } function someFunction1() { SpreadsheetApp.getActiveSheet().getRange("A1").setValue("Hello from someFunction1"); } function someFunction2() { SpreadsheetApp.getActiveSheet().getRange("A2").setValue("Bye from someFunction2"); }
In this separation approach, the menu created from the library call is displayed correctly in the spreadsheet, however when using the option from this testing menu I get an error message, for example: "Script function someFunction1 not found"