-
Goal: Query should be disabled on pageload when it does not match a value within a transformer
-
Steps:
-
Checked if the "disable query" statement is actually true
-
Set page load delay to 2000ms to make sure that the transformer has a value
-
-
Details: the query "getCurrencies" should only run when the transformedEntity.assetId value is given. For some reason it always runs on page load, even if the assetId from the transformer is null. I guess that it has something to do with the transformer that doesn't have an initial value when the page is loaded (just moments later when another query was executed). I have many components in that app that include a hide logic based on values of the transformedEntity and everything works fine for that. After the 2000ms delay the transformedEntity value is definitely there, so I don't know why the query still gets executed. Any ideas? Thanks for the help! And let me know if you need more info/screenshots.
-
Screenshots:
HI there @joshbchs, welcome to the forum!
This is indeed strange, but there may be a couple of things causing this:
- From your first screenshot, I can see the option "Run this query on page load" is not available, which makes me think that your query's run behavior is set up to automatic rather than manual. When it is set up to automatic it will run "on page load or when a variable it depends on changes". So to see if this is the issue, try changing your query's run behavior to manual.
You have already covered the other potential issue with the page load delay setting, so I'm pretty sure setting it up to manual will be your workaround.
Hi and thanks for your answer @MiguelOrtiz !
Thats a correct observation, the query's run behaviour is set to automatic.
But that is for a reason: the currencies should be listed in a dropdown when an assetId is given. When I would set the query to manual I would need a trigger, which I don't have.
You may think that its possible to just activate the "run on page load" option, but that's not the case because my inputs can change over the time (and then the query should run again -> automatic run behaviour).
Right. I guess you can't get around the query running upon page load if it is set to automatic.
You say you don't have a trigger. But you could definitely create a javascript query that watches the same variables that your getCurrencies query is watching and make it your trigger. Then you can change your run behavior to manual and have all the rules within your javascript query,
That would be a possible idea. But don't I have the same problem there again?
javascript query is always a manual query -> needs a trigger to be executed
Thanks for your ideas so far!
Found a way that worked for me
I added another condition to the "disable query" statement that checks if the transformedEntity value is null. So the query will be disabled on page load (because the transformer value is initially null). When then a value from the transformer changes, the second part of the condition will be triggered.
Looks like this now and works perfectly fine!
{{ !transformedEntity.value || !transformedEntity.value.assetId}}