I will distribute a spreadsheet with onOpen menu among several users. I would like to keep the menu definitions and functionality within a Library, so if I add some menu options or update some functions, everyone using that spreadsheet will get updated automatically.
So far, on the spreadsheet script I have only this simple code:
function onOpen() {
myLib.loadMenu();
}
The menu loads on the spreadsheet without a problem, however no matter how I named the call on the menu and the actual function (with or without myLib.) I always get an error "Script function doSomething could not be found" when using an option from that menu.
Any idea on how should I name 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 being able to add more options to that spreadsheet menu from the library, without having to update every user's spreadsheet.
This is sample code all included in the spreadsheet script, no library been used yet and it works without problem
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");
}
What I want to do is get the same functionality, but splitting the code between the spreadsheet script and a library, as follow
On the spreadsheet script
function onOpen() {
xsLib.testMenu();
}
On the 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");
}
On this splitting approach the menu built from the library call shows correctly on the spreadsheet, however when using an option from that Testing menu, I get a message error like: "Script function someFunction1 could not be found"
See Question&Answers more detail:
os