I've been wrestling with getting query return metadata from a query triggered from JavaScript, something like this:
await bcQuery.trigger( {
onFailure: function(error) {
console.log('failure error');
console.log(error);
},
onSuccess: function(queryResults) {
console.log('success metadata');
console.log(bcQuery.metadata);
}
});
The query results come back in an onSuccess clause no problem, but accessing the metadata of the result is a no-go. I've come to think of the JS query environment as a copy of the existing state at time of execution apart from the query results puncturing back through it. Is that an accurate way to think about it?
It seems that if I trigger a second JS query in the onSuccess clause that just prints out the metadata, that works great, so I guess the environment is not a spawn of a copy but a fresh copy of the top-level environment I can also add a success event handler on the original query (bcQuery in the above example), one that just copies the query metadata into localStorage, and then this Javascript clip can poke into localStorage and pull the metadata from there. But will that sync properly, I mean will the bcQuery success event handler complete before the JS query above continues into onSuccess?
I can't help feeling like I'm just missing some simple way to get the metadata Is there one and I'm just missing it? Please say yes
Thanks for any thoughts!
EDIT: Oops, I think I'm wrong about localStorage... just re-tried this with both localStorage and temporary state and I think I was just seeing values from previous queries. gah!