cancel
Showing results for 
Search instead for 
Did you mean: 

Dashboards - action triggers on page load

Nick_Mospan
New Contributor III

I 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_0-1628310860367.png

 

1 ACCEPTED SOLUTION

dcrossey
New Contributor III
New Contributor III

Hi Nick,

Using the following as an example:

dcrossey_0-1628602004747.png

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.

dcrossey_1-1628602185637.png

If I refresh the screen, the default text "Hello World" is present:

dcrossey_2-1628602220516.png

or if I click reset text it will add "Hello World (again):

dcrossey_3-1628602245400.png

Button Actions

dcrossey_4-1628602278966.png

Virtual query

dcrossey_5-1628602306292.png

Result

dcrossey_6-1628602323004.png

Output mapping

dcrossey_7-1628602345131.png

 

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);

}

 

 

David

View solution in original post

6 REPLIES 6

dcrossey
New Contributor III
New Contributor III

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 

David

Nick_Mospan
New Contributor III

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.

dcrossey
New Contributor III
New Contributor III

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).

David

Nick_Mospan
New Contributor III

How do I set triggerEnabled from an action (e.g. click on a cell in a data grid)? Isn’t that the same problem as setting the original view state to null?

dcrossey
New Contributor III
New Contributor III

Hi Nick,

Using the following as an example:

dcrossey_0-1628602004747.png

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.

dcrossey_1-1628602185637.png

If I refresh the screen, the default text "Hello World" is present:

dcrossey_2-1628602220516.png

or if I click reset text it will add "Hello World (again):

dcrossey_3-1628602245400.png

Button Actions

dcrossey_4-1628602278966.png

Virtual query

dcrossey_5-1628602306292.png

Result

dcrossey_6-1628602323004.png

Output mapping

dcrossey_7-1628602345131.png

 

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);

}

 

 

David

Nick_Mospan
New Contributor III

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.