cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way for single blox button to do 2 different actions ?

Wojtek
9 - Travel Pro
9 - Travel Pro

I would like blox button to perform 2 different actions, lets say change granularity action and change dashboard filter with single click.

Is this possible? so far when I try each action requires its own button.

Any help would be welcome.

Wojtek

6 REPLIES 6

keerthan
8 - Cloud Apps
8 - Cloud Apps

Hi Wojtek,

Yes you can write 'Custom Actions' to do multiple actions with a single button

Thanks & Regards

Keerthan

Wojtek
9 - Travel Pro
9 - Travel Pro

HI @keerthan thanks for suggestion, although it is going to be tricky for me. Need to write new  custom action based on the one I had written by another dev and include now functionality from build in filter action. 

Is there no option for one action to trigger another one in other words is it possible to create custom action which will take other actions as parameters?

Thanks,

Wojtek

@Wojtek I don't think we have that option for 'Custom Actions'. But I can help you with the script if you elaborate more on the requirement

Thanks & Regards

Keerthan

HI @keerthan 

Appreciate your help on this, hopefully other will benefit from it too.

I attached template for my blox with 2 buttons.

2actions_blox.PNG

First button is using custom action SwitchPanelItem which swaps items from this blox to destination blox by panel and item number. Im using it to change granularity here. whats important it can modify any number of widgets (3 in this example):

{
            "type": "switchPanelItem",
            "title": "Day Granularity",
            "style": {
                "width": "150px",
                "background-color": "#a6a6a6"
            },
            "data": {
                "actionDetails": [
                    {
                        "targetWidget": "630cb7bf6c6a680037e5dc99",
                        "sourcePanel": "0",
                        "sourceItem": "0",
                        "destPanel": "0",
                        "destItem": "1",
                        "dimName": "Date"
                    },
                    {
                        "targetWidget": "630cb7bf6c6a680037e5dca3",
                        "sourcePanel": "0",
                        "sourceItem": "0",
                        "destPanel": "0",
                        "destItem": "0",
                        "dimName": "Date"
                    },
                    {
                        "targetWidget": "630cb7bf6c6a680037e5dc95",
                        "sourcePanel": "0",
                        "sourceItem": "0",
                        "destPanel": "0",
                        "destItem": "0",
                        "dimName": "Date"
                    }
                ]
            }
        }

 The second action is standard filter action to modify dashboard date filter, in this example changing it to last 8 days:

{
            "type": "Filters",
            "title": "dashboard filter - last 8 days",
            "style": {
                "width": "220px",
                "background-color": "#a6a6a6"
            },
            "data": {
                "level": "days",
                "filters": [
                    {
                        "filterName": "History",
                        "filterJaql": {
                            "last": {
                                "count": 8,
                                "offset": 0
                            }
                        }
                    }
                ]
            }
        }

also here is switchPanelItem action code:

payload.data.actionDetails.forEach(function (a) {
    var w = payload.widget.dashboard.widgets.$$widgets.filter(i => i.oid == a.targetWidget)[0];
    w.metadata.panels[a.destPanel].items[a.destItem].jaql = JSON.parse(JSON.stringify(payload.widget.metadata.panels[a.sourcePanel].items[a.sourceItem].jaql));
    if (typeof a.dimName == 'string') {
        w.metadata.panels[a.destPanel].items[a.destItem].jaql.title = a.dimName;
    };
    w.changesMade();
    w.refresh();
});

 The challenge is to make those 2 actions into one so they can be executed with single button. Important is to be able to switchPanelItems for any number of widgets.

Again, thanks for your help on it.

Wojtek 

keerthan
8 - Cloud Apps
8 - Cloud Apps

@Wojtek 

I have removed 'dashboard filter last 8 days' button and kept only 'Day Granularity' button. And updated your 'switchPanelItems' script to filter 2nd action ( last 8 days dashboard filter ) as well

Let me know if this is what you wanted

 

keerthan_0-1663611144779.png

 

Blox changes : 

Note : Please change the content under 'dateFilters' section to match with your dashboard date filter metadata

 

 {
            "type": "switchPanelItems",
            "title": "Day Granularity",
            "style": {
                "width": "150px",
                "background-color": "#a6a6a6"
            },
            "data": {
                "actionDetails": [
                    {
                        "targetWidget": "628f953a600ec2002b8c2580",
                        "sourcePanel": "0",
                        "sourceItem": "0",
                        "destPanel": "0",
                        "destItem": "0",
                        "dimName": "Date"
                    },
                    {
                        "targetWidget": "628f900a600ec2002b8c2571",
                        "sourcePanel": "0",
                        "sourceItem": "0",
                        "destPanel": "0",
                        "destItem": "0",
                        "dimName": "Date"
                    }
                ],
                "dateFilters": {
                    "dim": "[DIM DATE.Date (Calendar)]",
                    "title": "History",
                    "column": "Date",
                    "table": "DIM DATE",
                    "datatype": "datetime",
                    "level": "days",
                    "filter": {
                        "last": {
                            "count": 8,
                            "offset": 0
                        }
                    }
                }
            }
        }

 

 

'switchPanelItems' custom script changes : 

 

 

payload.data.actionDetails.forEach(function (a) {
    var w = payload.widget.dashboard.widgets.$$widgets.filter(i => i.oid == a.targetWidget)[0];
    w.metadata.panels[a.destPanel].items[a.destItem].jaql = JSON.parse(JSON.stringify(payload.widget.metadata.panels[a.sourcePanel].items[a.sourceItem].jaql));
    if (typeof a.dimName == 'string') {
        w.metadata.panels[a.destPanel].items[a.destItem].jaql.title = a.dimName;
    };
    w.changesMade();
    w.refresh();
});

// Dashboard date filter
const datefilter = payload.data.dateFilters

prism.activeDashboard.filters.update(
    {
        'jaql': datefilter
    },
    {
        'save': true,
        'refresh': true,
        'changesMade': true
    }
)

 

 

 

 

 

HI @keerthan 

Sorry for slow response on this. Thank you for providing code.

I am having a problem with part of code which updates dashboard filter. Works great when you try to update date filter which is on the same level so if dashboard has week 20 of 2022 selected and I want to update to This week using count:1 and offset:0 then it works! updates existing filter. 

In a different scenario though If I had dashboard filter at months level , lets say July-2022 selected and I want to updated to This week then new filter is created instead of updating existing one.

I think what would work is deleting the filter first by name ("title") as the code creates filter if it's not there.

Any chance you can add this update 🙂

Thanks,

Wojtek