2

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?

Jose M Vidal
  • 8,816
  • 6
  • 43
  • 48
  • Hello, Jose! I have exactly the same situation. If you found a solution, prompt what to do to make it work? Answers from google-apps-script-issues didn't help me – uselesssmile Jan 15 '15 at 07:03

1 Answers1

1

I was wondering the same thing. So far haven't seen an real answer on this. My answer is not the best, but I managed a workaround doing this on the script:

function test() {
  Test.test();
}

I'd love to know the real solution for this.