0
votes

I am using sort of wrapping functions to add widgets to UiApp, like the sample below

function newButton(text, handler, callBack) {
  var app = UiApp.getActiveApplication();
  return app.createButton(text).addClickHandler(app.createServerClickHandler(handler).addCallbackElement(callBack));
}
  • it works fine when used within the same script like below

    panel.add(newButton("Submit", "myHandler", panel));

  • but when including newButton function within a Library (ex. myLib) and it's called as myLib.newButton, I would get an error: "Error encountered: Unknown macro myLib.myHandler"

    panel.add(myLib.newButton("Submit", "myHandler", panel));

Any way of avoiding this problem, while keeping myHandler in the current script (not in myLib)? Thanks, Fausto

1

1 Answers

1
votes

Yes it can. In your current script (wherein you imported the reference to the library) create;

function myLib.myHandler(){
}

As your handler (string) keep passing the name 'myHandler'. The above function will be called by the button created in your library script.

It seems like apps script is using this namespace structure to avoid name collision.

You should keep in mind that this could purposely be not-documented by google for a reason. Maybe this current structure could be changed in the future. Or maybe im just being paranoid ;-)