Home › Forums › KX Solutions › Dashboards – action triggers on page load
-
Dashboards – action triggers on page load
Posted by nick_mospan on August 6, 2021 at 12:00 amI created a virtual query which clears some view states and set it as data source for an action. It works as expected when action is triggered but I found out that it is also executed at page load. If I pass parameters to the dashboard they are now cleared because of this side effect.
How do I make sure that the query is only triggered by an action?
Here’s the query:
nick_mospan replied 9 months ago 2 Members · 6 Replies -
6 Replies
-
Hi Nick,
You could try passing in a boolean viewstate triggerEnabled to your virtual datasource, which has a default value as false when the page loads to prevent it clearing.
Something like:
function (x, triggerEnabled, callback){ if(!triggerEnabled) { callback(x) // i.e. just return x without modifying } else { callback ({ // i.e. your custom clear logic }); } }
Set the viewstate to true when you actually want to clear the viewstates.
You can also map an output viewstate to reset the triggerEnabled viewstate to false after execution.
Hope this helps!
Cheers,
David
-
Hi Nick,
Using the following as an example:
When I come to the dashboard, the text viewstate is present. There is a virtual query however it does not wipe this viewstate.
When I press clear, it activates the viewstate and clears the text.
If I refresh the screen, the default text “Hello World” is present:
or if I click reset text it will add “Hello World (again):
Button Actions
Virtual query
Result
Output mapping
Unfortunately I’m not able to attach json (example dashboard) on the Community portal yet, however I’ll drop you an email to see if it helps solve your issue.
Kind regards,
David
—
Virtual Query
function (source, enabled, callback) { var result = { meta: { k:11, v:11 }, columns: [ "k", "v" ], rows: [] }; if(enabled) { console.log('Clearing viewstates'); result.rows = [ {k:'text', v:null}, {k:'triggerEnabled', v:false} ]; } else { console.log('Returning current'); result.rows= [ {k:'text', v:source}, {k:'triggerEnabled', v:enabled} ]; } callback(result); }
-
Hi David,
Thanks for reply. However I don’t think this solution will work as the fact of setting triggerEnabled to true will trigger the query, giving similar side effect.
-
Hi Nick,
I’ve updated the skeleton to make it a little clearer. When the page first loads, this virtual query will run but will not clear your parameters if you return the input without modifying.
It should only run the clear logic when you set the triggerEnabled to true (intentionally).
-
How do I set triggerEnabled from an action (e.g. click on a cell in a data grid)? Isnt that the same problem as setting the original view state to null?
-
Thanks David, I got it working now. I was confused at first as there’s no way to set a view state to a value in an action for a DataGrid, it can only copy from a cell. I adapted your solution and used the Row Id column instead of ‘true’, so in my case triggerEnabled is a string, not a boolean.
Log in to reply.