Query returns no data on first run


I have a query that when run for the first time will not populate a table with dynamic columns enabled. A user selects a checklist from a dropdown menu, the change event fires and runs my JS query. Within this JS query, I trigger a database query to return questions from a database, set the hidden value of the table to false, and returns the question data I need to populate the table (code below). However, when this first runs the table does not get populated. I can see the data is returned by hovering over the returned data in the query. But when they select another checklist, the query runs again and the table is populated. I'm sure I am overlooking something but I can't seem to figure it out. Any help is greatly appreciated.

Change Event of the dropdown code:

const chklist = ChkListDrpDwn.value; //this value is correct

switch (chklist){
  case "gen_assembly":
    await GenAssyQuestions.trigger();
    return GenAssyQuestions.data;
  case "roof_inspection":
    await RoofInspectionQuestions.trigger();//this gets the data I want from the table
    return RoofInspectionQuestions.data;//this returns the questions to the table as the data source
    return [];

EDIT: I ran a console.log to show the data after the query is trigger and for some reason it's null.
EDIT2: Also, this only happens if I select Roof Enclosure Inspection first. If I select another checklist first it runs as expected and the table is populated.

i hate to be the one to ask these types of questions but:

  • do GenAssyQuestions and RoofInspectionQuestions have the same code?
  • do they get data from the same database?
  • using the State viewer, does the state of the query ever change after it's triggered?
  • have you checked the state and values for editTable before trying to use setValue()?
  • is the Roof query set to watch inputs or just trigger on call?

to me, it sounds like there's a type-o either in the database or maybe in editTable

Thanks for the reply Bob!

1.) GenAssyQuestions and RoofInspectionQuestions do not have the same query. Each are selecting columns from a specific table. GA - select * from ga_questions order by id and Roof - select * from roof_inspection_questions order by id

2.) Yes it's from the retool database, just different tables.

3.) The state of the drop down code, when I select Roof Enclosure first, does not change. However, RoofInspectionQuestions state changes and shows data. Also when I select Gen Assy first the state for the JS code doesn't change either. Only the Questions queries state changes.

4.) I ended up just commenting those lines out for setting the editTable value. Didn't change anything unfortunately.

5.) Roof was configured to run when triggered but gen assy questions wasn't. I changed it to run only when triggered but that didn't solve the problem either.

I'll keep looking and see if I come across any typos

thanks again!

=( sorry, the only thing I can think of right now is to try wrapping that case in a try/catch.... you might get lucky there, I hope. I'll let you know if I come up with anything later on.

oh, it sounds dumb, but i had to refresh the page once to make some weird stuff stop happening. you've probably done this, but I'm grabbing at thin air here as the straw i was holding onto disintegrated. the other odd thing i've had to do is delete a component or query then remake it.

Thanks for the attempt! Idk what happened but now it's not working at all unless I manually click run on the drop down code or the other two queries. i might just scrap it and try to dynamically populate the table another way

I have done the refresh unfortunately. I did create a new query (query20 - select * from enclosure_roof_inspection_questions order by id) and in the code for the change event of the drop down is just: await RoofInspectionQuestions.trigger(); console.log(RoofInspectionQuestions.data); and I still get null from the console.log. I'm at a loss now because I don't see why that won't work, I even created a new script with just the trigger and console.log for the data but still no change. still manually running the queries or script works as intended. it's only when using the .trigger() method.

@bobthebear Hello again,

I was able to find a workaround. I changed the RoofInspectionQuestions and GenAssyQuestions queries to run automatically. Then when the drop down selection is changed I just return the data from the queries in a switch. now I get my expected behavior, populating the table with the questions from the selected query. I'm not sure why the way I was going about it worked this morning but this afternoon stopped working but it's working now so that's really all that matters.

THanks again for your help

  • Skylar