- My goal: Be able to reuse the same JS query in multiple apps
- Issue: I don’t see an option to export a JS query
- Steps I've taken to troubleshoot:
- Additional info: (Cloud or Self-hosted, Screenshots)
Hey @bailakahn, thanks for writing in! Great question. If you would like to reuse the same JS query in multiple apps, you can look into the Query Library. It lets you create, run, and share queries across your organization and between Retool apps. Let me know if you have any questions getting that set up! ![]()
Hi @ChiEn ,
Thank for your answer.
The query library indeed works very well for SQL, API and other resources.
But I am looking into reusing a JS Query. For JS query I don’t see the option to export it to a “Query Library“.
Maybe I am missing something here. Can you check and let me know?
Hey @bailakahn,
If you want to reuse the same JS query across multiple apps, there is a reliable way to do it in Retool. You can create a manual-trigger Workflow and move your JS logic into that workflow. Inside the workflow, you can write your JavaScript, process whatever data you need, and return the response.
Once that’s set up, any app can simply import the workflow and trigger it whenever needed, just like calling a shared function. This gives you a single source of truth for the logic, keeps everything consistent, and removes the need to copy/paste the same JS code into every app.
At the moment, this is the most scalable and maintainable approach for reusing JS logic across multiple Retool apps.
Hope this helps!
Hey again @bailakahn yes you are absolutely right, I overlooked that.
Thanks @WidleStudioLLP for the Workflows suggestion!
Only if restriction of Workflows is not an issue for you.
Another option is to define it in Preloaded JavaScript instead. You can find it under Settings, then Advanced settings, then Preloaded JavaScript. Screenshot below. Let me know if this is helpful at all!
Hello again @bailakahn, happy new year to you!
Did you get a chance to look at the post above? Was it helpful at all? Let me know! ![]()
Of course @bailakahn happy building!! ![]()
