I have the following code.gs
function test() {
Logger.log("Whoo hoo! test() called");
}
function showPopup() {
var html = HtmlService.createTemplateFromFile('index').evaluate().setWidth(400).setHeight(300);
SpreadsheetApp.getUi().showModalDialog(html, 'Click the button');
}
along with this index.html
<div>
<input type='button' onclick='google.script.run.test()' value='Test'>
</div>
These work fine: after running showPopup() I click on the button and the message appears in the logs example.
The problem comes when I add this project as a library to another spreadsheet, using the "Resources->Libraries..." menu item. Let's say I give the library the name "Test", then on the new spreadsheet I run Test.showPopup()
, it puts up the popup. But then when I click on the button it does not call the test() function.
Instead, the console on the spreadsheet complains that "undefined is not a function". The problem appears to be that google.script.run.test() does not work when code is shared using the Libraries manager. It wants something like google.script.run.Test.test(), but I tried that and it didn't work either: "Cannot read property 'test' of undefined".
Is there some way I can use google.script.run in a shared (library) script?
or some other way I can re-use my code on other spreadsheets without having to cut-n-paste all the files to each one?
Ah, it looks like someone else reported this as a bug. Shucks. Any workarounds?