Trigger query inside module from host app

First off, our team is so excited about all the big improvements that have been made lately... Retool is getting so much better!

As we move to a more module based setup, we want to be able to trigger a query inside a module from the parent app. For example: we want to be able to clear all the fields inside the module at once.

It seems like I may be able to do something using these autocomplete functions but they all throw errors and don't behave as expected.

The other option would be to do something by passing in an input value, but I'm not sure how to handle state there (once it's been clicked once, how to reset and let it get clicked again).

Does anyone have ideas?

2 Likes

Hey Alex! First, thank you for the kind words! Will pass that along with the brilliant team working on the new components.

Second, here's a post that goes over triggering a module query from a parent app!

[edited 09/28/22 to include a link to the how-to post instead]

Hi! This is super helpful to me right now as I'm working on trying to trigger a module query from the parent app. I think I'll be able to work through it with the text alone, but the screen shots would be super helpful. Unfortunately, they aren't showing up in the response. Would someone from the Retool Team be able to re-add them?

Thanks!

1 Like

Ah, thank you for the callout @bryan! How is the above image displaying now?

I can see it now, thank you! :slight_smile:

There were two images on the initial reply, though. Does this cover both?

It does! The first was actually entirely irrelevant/I must have attached it by mistake :sweat_smile:

This technique needs to be in your docs for modules. Took me all day to figure this out and end up in this thread! Anyway, got it working in the end.

Ooh, great point. Will reach out to our docs team to see how we can collaborate to get this to be more visible :slightly_smiling_face:

1 Like

I want to do a similar thing as alex-godin. And the solution seems a bit hacky for what I am trying to do.

I created an 'init' script for my module, setting all the default values whenever the module is opened in the main app. I simply want to trigger this script manually, without relying on input changes.

A big appeal of the of the business plan is the ability to make a lot of small modules, similar to how I would make class in regular coding. The reason I simply want to run init is also because of my coding mindset. In my opinion, a module should work independently of the parent app. Having to create an input field with a query from the parent app to simply run my init script ruins this independence and thus the appeal to make a lot of modules.

It seems my way of working/thinking is wrong though, it there a better way to do this (clear/ init module in parent app without having to create an input in the module for each parent app in which it is used)

EDIT:
Based on this thread, I found a good setup to run module scripts from the parent app which works well for me. Looking forward to share it soon.

2 Likes

I'm so glad you found a solution here! Let me know if you have any questions I can help answer :slight_smile: