System.db.refresh and "Wait Until Refreshed"

Hello All,

I’ve recently run into an issue with the way one of my scripts works when a table’s data is being refreshed. The actual scenario is a little different than this, but for simplicity I’ve reduced it to the following:

Table data is bound to a SQL query. The query pulls in a lot of data and takes a second or two to complete a refresh once system.db.refresh(table,“data”) is called.

I also have a button that selects a random value. Once the random value is generated it loops through every row in the table and checks for that random value in one of the table’s columns. Once it finds a match it sets the table.selectedRow to that row and the script is done.

The issue here is that the looping through the table’s dataset takes place before the table data is fully refreshed, and sometimes the randomized value isn’t in the table until the dataset finishes refreshing. This means that the row is never found and therefore there is no change in selectedRow

So my question is: Is there any way to call a system.db.refresh on the table data but wait until that refresh has completed before continuing with the rest of my script (in this case the looping through every row)? I know I could potentially repeat the loop over and over until the row is finally found (meaning the data has finished refreshing), but that seems wasteful and risks an infinite loop.

Any clever ideas? Thanks!

Put the script that is currently on the button into the propertyChanged event of the dataset.

If your dataset is called “data”:

if event.propertyName == "data": # Put the code that checks event.newValue dataset here.