[how-to] Trigger a module query from the parent app

Currently, the best/only way to trigger a query inside a module FROM the parent app would be to use this workaround:

  1. Create a module input (this is a setting on the left side of the page when building your module) and set the value to be the parent query or the parent input that you want to use to trigger the module query. In this example, I want to trigger my module query whenever my parent app query, titled parentQuery, runs.

  2. (a) Create a "Query JSON with SQL" dummy query that runs (b) select * from {{input1.value}}. This watches for changes to input1 and triggers this query on any changes. Then, (c) add a Success event handler to this dummy query that triggers your target module query.

  1. Now, in your parent app, just make a change to whatever you set input1 to (in the module) and you should see the module query get triggered!

I've also attached an export of the module used in this example so you can look around if that's helpful at all :slight_smile: You can import this JSON file by clicking Create new (on your Retool organization's home page) > From JSON.

Trigger module query.json (8.4 KB)

3 Likes

I really need a way to clear one input field in our module.

My intuition would be to add a "Method" to the component, but that doesn't exists, so I try "Inputs" instead.

I press "Add Input", name it "clear", and set the type to "Query".

Then I add a "Success" handler that clears my input on the "Module Input Query", as that seems to be the only way.

Finally I add the module to an app and try to trigger the input. No matter what I try, "clear" is just a string, and the module only has a weird unusable "Set an output" method.

So that approach did not work. Then I tried to add a "Javascript query" to the module instead that does the same thing.

And the same thing happens. The "Javascript query" named "clear" is still just a string, no matter how I try to use it in an app.

I'd really love a way to add methods to modules - am I missing something? I feel like this is a common use case for modules :+1:

Related: Pass events back from Module

Hey @oles! I haven't been able to reproduce this just yet. Would you mind sharing some screenshots of your setup? And I assume the workaround above doesn't work for your use case?

@victoria your lovely support team was able to help me out!

They made a copy of my minimal reproducible app and module, and made a change I had not considered - and it worked!

I'm still not sure how it actually works, but passing in a "Temporary state" and using it as the "Default value" on an input in the module - causes it to reset on submit!

I'd still love for a better or clearer way to do it, like a "Method" or "Event" input type on modules, as this feels like a workaround, and not intuitive (for me, at least) :+1:

1 Like