Have 3 queries to populate only 1 table - conditionally

Hey All,
I'm new to retool and somewhat new to building apps with javascript. I am building a very simple inventory app. I have 3 different Postgres queries set up so the user can search based on conditions...This works fine, but I would like to populate a Table1 with the results of the most recent query of the 3. Ideally if you hit Submit1 Submit2 or Submit 3 it selects the correct query to populate Table1 (I'm trying to avoid multiple hidden tables, seems not pro) I have created a state1 and pass a number to it to help choose programatically which query populates the Table1.

I feel like I don't understand where to plugin the following code...Can anybody help me out?

ADAM

Screenshot from 2023-04-13 13-01-15

switch({{ state1.value }}) {
  case 1:
    {{ base_alice_query.data }}
    break;
  case 2:
    {{ base_column_alice_query.data }}
    break;
  case 3:
    {{ base_location_alice_query.data }}
    break;
}

Hey @ADAM_Betker, welcome to the community!

If you want to put JavaScript directly into a component input, you need to wrap the whole expression in double curly braces. Alternatively (and arguably better), you could put this code into a JavaScript transformer, and use the transformer value as the table data source.

Documentation: Transform data with JavaScript

I expect you may need to tweak your code by adding return to each case statement - this eliminates the need for break, too

switch ({{state1.value}}) {
  case 1:
    return {{base_alice_query.data}};
  case 2:
    return {{base_column_alice_query.data}};
  case 3:
    return {{base_location_alice_query.data}};
  default:
    // You can optionally include a default case with a return statement
    // in case none of the cases match.
    return null;
}

I hope this helps!