I assigned custom properties to my root container. I use one call to get a dataset via a named query. there are 10 columns in that dataset, I am retrieving one row of a database.
I assigned additional custom properties to grab the data from each of the columns I cared about.
SELECT *
FROM tasks
WHERE stepnumber = :myCurrStepNum
taskdata dataset is bound to that named query (getnextstep)
safetydata is bound to
{Root Container.taskdata}[0,"safety"]
Problem is the text from safety isn't there by the time it is drawing the text field displaying the safetydata so it just shows none. if I exit out, and look in the property editor it shows the custom property safety has data and clicking on it will populate that text field correctly.
I need some way to either refresh the safetydata custom property after taskdata dataset is populated (once query is complete) or some other way to retrieve and store the data because showing none is not acceptable. I hate to do 10 distinct queries to grab each piece of data.
I'd love to do the query from the previous screen when they hit the next button so the data is there but i don't know how to access the individual fields from the row and it seems most efficient to grab the whole row.
When you have an expression like this, and the data isn't there at startup (fairly common), the simplest solution is to wrap the expression in the try() function, and supply a fallback value to use/show/whatever until the actual data arrives. Like so:
This did not change the behavior. It seems to be loading the data from the previous row in the database until the query updates to point at the current row.
I have tried to do a system.tag.writeBlocking on the row index when they hit next on the previous screen but that update seems to lag. I would be fine if I could display "something else" until the query updates based on the new row index but instead it shows stale data and that is confusing or even dangerous.
I don't know how to query and store the row from the database that I need ahead of the display. I tried named query with the keyword into but that didn't work either.
Each screen is displaying data from a row in the database for that screen (task to be executed by operator). I don't know best way to trigger the query, parse the columns, and be ready for use when advancing to the next screen. The lag causing stale data to be displayed is unacceptable.
Is this the problem? It's initially using the previous step number in the where condition of the query?
Perhaps save the window with the default value in the text editor, and use scripting to populate the data instead of a binding.
Example:
# Updates the value only when the step number changes
# Assumes there is a custom property on the text field called myCurrStepNum,
# ...and that the step num is updated automatically in some way
if event.propertyName == 'myCurrStepNum' and event.newValue is not None:
query = 'SELECT safety FROM tasks WHERE stepnumber = ?'
event.source.text = system.db.runScalarPrepQuery(query, [event.newValue], 'NameOFDatabase')