When I create a script within a spreadsheet using UiApp, I have a button with a server handler which ends in an underscore. If I run the script from within the spreadsheet then it works fine, but if I add this project into another sheet and run it then I get an error saying the script function is not found. It has no problem finding functions that end with an underscore when they are used in the code, it just seems to be when they are called from a server handler.
To replicate:
Create a new spreadsheet
Insert the code:
function buildForm() {
var app = UiApp.createApplication();
// show that calling a function ending in underscore works
var labelText = getLabelText_();
app.add(app.createLabel(labelText).setId("label"));
var handler = app.createServerHandler("clickHere_");
app.add(app.createButton("Click Here",handler));
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.show(app);
}
// This is just to show that underscore on the end works as long as it is not a server handler
function getLabelText_() {
return "label text";
}
// called from server handler
function clickHere_(e) {
var app = UiApp.getActiveApplication();
app.getElementById("label").setText("You clicked there");
return app;
}
Run the code and see that it works as expected
Create another spreadsheet, add the first spreadsheet as a library and call it MyCode. Make sure you have saved a version etc etc.
In the new spreadsheet, insert the code:
function runIt() {
MyCode.buildForm()
}
Run this code, note that getLabelText_() works fine and the UI is created, but when you press the button, the function not found error will appear.
If I remove the underscore from clickHere_(e) and change the server handler accordingly, then it works.
Is the only solution to remove the underscore from the end of all functions called by a server handler?