readRecords simple question

This is simple demo code for createRecord and readRecords. What am I missing? Thanks!

  • Carol

What I expect to happen:
Create a table with 2 rows, then read the table back. After a user chooses a state in the dropdown, the text fields are updated.

What actually happens:
The createRecords are executed and the console.logs run. When I pause at the readRecords line, then StepIn, execution skips past readRecords completely. numRecords doesn’t exist and nothing is written to the console. Same for both getStateCases and getRegionCases. The textAreas on the screen are set to 0, since the readRecords didn’t read data.

*** LINK ***

readRecords is a function that sets up a callback function. That function is called at some later time after the records are retrieved from the database. If you read through the code ignoring the callback function, which you should, what you see is that getStateCases and getRegionCases willl always return 0.

Anything you want to do with those records must be in the callback function.

I would also note a few things more. If you want just the texas record you can specify that in the readRecords call. Each time the program runs you add TX and OK to the database again.

A better way to do that would be to import a csv file with all the states you want. Then you can initialize the drop down with setProperty("chooseState","options",["TX","OK",etc etc])

@carol.ramsey After running your code a few times, I think I understand what’s happening.
As @jdonwells mentioned, each time your program is run, you recreate the data for TX, 500 & OK, 400 which makes your dataset larger. Eventually, that could cause a performance problem.
Your readRecords() function is reading the data correctly.
To display the table data in the text fields, you should setText() in the getStateCases() function.
I hope this adds clarity.