Load saved Query back into QueryBuilder

I am using the Query Builder and wonder if it is possible to be able to load an existing set of query criteria back into a QueryBuilder component next time the app is loaded?
I can't seem to see a way to so it, but apologies if i'm just being daft.

Hey @mkeywood! I believe you should be able to do this using the value property in your inspector:

If you have your query format saved somewhere, like lets say in a Transformer, you can reference it like so:

Screen Shot 2021-07-07 at 6.52.29 AM

The value property takes a JSON object, so you'd probably want to export that format from an already filled in query builder and put it in a Transformer or temp state somewhere.

Hope this helps!

Thanks @justin for the response.
I tried that, but maybe I am getting something wrong (probably :slight_smile: ).
I have a state called allQueries which is an array, with each element being an object with two keys - name and value.
name is being set to a text box for a free text query name, and value set to the value field as you say:
allQueries.setValue(allQueries.value.concat([{ "name": queryName.value, "value": querybuilder1.value }]));

So if I look at the first query in that list (allQueries.value[0].value), it show's me:

But when I try and set it back with the following, it doesn't seem to do anything :frowning:
querybuilder1.value = allQueries.value[0].value

Can I set that value programmatically?

@mkeywood the .value property is read only. You'll need to set the value via the UI that I mentioned above.

Ah OK, thanks. That's a real limiting factor as I need a way of recalling 'saved' queries to allow simple futures tweaks / edits.
That's a shame. I'll see if i can use something other than QueryBuilder.

Thanks again for your quick responses and help :slight_smile:

1 Like

For sure! I think you can just do all of that logic in a Transformer (which query we want to set the value as, when, etc.) and then just reference the value of that transformer like above. But I totally understand that it would be easier to programatically set :confused:

Thank @justin :slight_smile: