I am trying to run a SQL query and then based on the result either continue on with a row action in a table to delete a record from the SQL DB or display a message to the user letting them know that it is no longer eligible for delete. The issue I am having is within the row action of the table. Once I populate the table, if a user immediately clicks the row delete button on the right side of the selected row, the data in the selected row ID (or table per below) is not available to be passed into a SQL query to check the SQL DB to see if the delete is still valid. Here is what the row action of the main table looks like:
// This query gets the data to make sure the selected row is there to delete
await qry_SupportingDocDeleteIntegrityCheck.trigger();
// The data from the integrity check query gets populated in this table
await tbl_SupportingDocDeleteIntegrityCheck.refresh()
//Get the number of rows returned from tbl_SupportingDocDeleteIntegrityCheck
const is_file_ID_delete_eligible=tbl_SupportingDocDeleteIntegrityCheck.data.length
// Test value
await console.log (is_file_ID_delete_eligible)
The value for is_file_ID_delete_eligible is always null despite there being data in the table.
However, after the first click on any delete row action it works just fine.
Hi @dsuby,
Can you provide me with the exported JSON file from your app so I can take a look at these queries and your table? (I'm having trouble following your description above and it might be easier for me to just see the actual code. )
After playing around with this some more I have a feeling this is happening because await qry_SupportingDocDeleteIntegrityCheck.trigger(); and await tbl_SupportingDocDeleteIntegrityCheck.refresh(); is not completing prior to the creation of 'is_file_ID_delete_eligible'.
@dsuby,
Yes, it looks like this variable is likely being set before the query runs. Instead of running it all in one script, you could run a separate script in the success event handler of your first query (the one that the variable is dependent on). In this script, you could then set the variable and run the rest of the code.
This could work but if there is a validation error detected I am adding the validation error message to an array which later gets displayed to the user with all of the validation errors. I can try what you suggested but I am wondering if I can pass an array back to the calling function so I can still have all of the validation errors in one validation error array to be displayed to the user.
@dsuby,
Are you referring to the ValidateSupportingDocFile js query that provides the array of error messages? This is run when you drop a file into the dropzone, so I think this will not be affected by your moving of the setting of the 'is_file_ID_delete_eligible' variable in a success handler. (or am I misunderstanding?)
In the js query ValidateSupportingDocFile there is an array called errorMessages. Is it possible to return a value from the success event of the query that can then be added to the array errorMessages?
@dsuby,
Maybe you can make the errorMessages array a separate variable and just update it with your different queries. Then you won't rely on what is being returned in a specific query to update it. In that success query, you can just add whatever you want to the current errorMessages.