Table selectNextRow() not working after state update

  • Goal: To select the newly added line to the table

  • Steps: I have logged the state and it shows correctly. but when i trigger the selectNewRow it resets to first row, i am assuming since the table has not yet updated with stated yet...?
    i have the keep variable reference in sync on and that made the state keep in sync and the log proves that. But i have to have a small delay in order for it to work properly for now as a patch. But there must be something i am missing right?

  • Details:

await edit_part.trigger();
await add_part.trigger();

console.log(MR_Data_Parts.value)
await new Promise(resolve => setTimeout(resolve, 90));
await table3.selectNextRow()

Hey Paden, a Retool JS script is not async, so it won't "wait" when the await keyword is used when used at the top-level scope.

Instead you can return a Promise and use an event handler for code that should run after the asynchronous calls complete. Event handlers will be called after the Promise resolves.

So your javascript might look like the following:

return Promise.all([edit_part.trigger(), add_part.trigger()]);

And you'd add a Success Event Handler to this query that might look like:

table3.selectNextRow();

You can see more examples in our docs or check out this Community post for a deep dive into how to think about async functions when scripting in Retool.