Custom Libraries

  1. My goal: reuse some complex JS classes we have built
  2. Issue: Libraries
  3. Steps I've taken to troubleshoot: extensive testing
  4. Additional info: (Cloud or Self-hosted, Screenshots)

The Libraries under App settings seems to suggest that one can import custom js scripts:

But i can’t seem to get this to work. Is this limited to retool sanctioned custom libraries? I have some classes for mime, html rendering and statement and savings statement rendering that are fairly complex and re-used across a couple of apps and workflows. I’ve already resigned myself to having to manually insert those base and child classes into the specific workflow steps they are consumed in, but was hoping to not have to do that in the UX side. Yet that does not seem to be the case.

Hi @David_Bolen,

Are you getting an error message when trying to invoke the Class from the library that you are importing in a Javascript query?

Check out our docs here on using custom javascript libraries.

Thank you Jack. I have read that page several times. And tried a number of different things. No matter why i try to define in my custom library, the results are always the same

Hi @David_Bolen,

I just did some testing and with a simple example I was able to get a custom JS library to load and work in Retool.

You made need to slightly tweak the formatting of the library, such as how the Class is bound to the global scope to allow it to work as intended.

(function (global) {
  function helloWorld() {
    return "Hello, World!";
  }
  global.helloWorld = helloWorld;
})(typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : this);

As long as you put your code where the helloWorld function is, inside of function (global) it should work. If not let me know!