Hi All!
I'm running into some trouble getting SQL query results into a table, when the SQL query is triggered by a JS query.
Background:
I have a search form with several input fields that are all optional criteria. I could try a complex where-clause in the SQL query that will ignore filtering/searching when any of the parameters are NULL/empty strings. (If anyone knows of a stable/reliable/performant query for such a case, please share! )
Current Implementation
However, I thought it could be easier to build the query through JS with a "base query" string and adding the logical phrases to the where-clause for each input field that was not empty. Outputting the final query string and running it in my local DB worked.
Next I tried updating the "query1" (the query object, which is empty when viewing the General tab) with the JS-constructed query string, and triggering it with simple logging.
query1.query = queryBase;
console.log('Showing the query from the query object...');
console.log(query1.query);
query1.trigger({
onFailure: function(data) {
console.log(data);
console.log('MY QUERY FAILED!');
},
onSuccess: function(data) {
console.log(data);
console.log('MY QUERY RAN SUCCESSFULLY!');
}
})
Whenever my JS ran, I could see in the browser's console window that the SQL query object query1 did save the query string, and ran and finished successfully. From what I've gathered so far, the result set is supposed to be passed back into the onSuccess callback function through the "data" argument. But any attempts to save or display that data have failed.
I even tried adding scripts to the Success event handler of the SQL query in the query1 General view. Again, no data from the query result is preserved.
Does anyone have any other ideas to resolve this? Thank you in advance!