How to use preloaded javascript in query library

I added preloaded javascript at organization level by writing code at "Advanced > Preloaded Javascript"

And I tried to use it in query library (mysql)

But It's not working I expected.
Using {{ example() }} or {{ window.example() }} both not worked.
How can I use preloaded javascript function in query library?

I really need to use functions in query library to improve reusability and code quality.

Hi @joshua1 welcome to the community! Were you able to figure this out? If not, I'll inquire internally about the best course of action you can take. Thanks!

Nope. I couldn't find a way to solve the problem.
Please inquire internal team about this problem. thanks.

Hey @joshua1!

This currently isn't possible within Retool but it is something on our radar. We'll pass it along here when this is fixed but for now the only options I can think to give you are:

  1. Write the code directly into your query library query
  2. Copy the query into each app you'd like to use it in
  3. Use the parameters to pass through the necessary globals at run time

If you can share a little more about your specific use case there may be a better option than this though, let me know!

Case 1, 2 are not the way I want to choose.
It have to rewrite code everywhere I want to use.
I'am trying to centralize code into global preloaded script.

I don't understand Case 3 solution. What's the meaning of "Use the parameters to pass through the necessary globals"? Can you explain it in more detail?

That's understandable. The idea behind Case 3 is to define a variable in your QL query that accepts the value for the global function you've defined:

Hopefully, that would let you cut down on some of the duplication you'd need to do but it's far from ideal as well.