Forum Discussion

ssoltz's avatar
ssoltz
Cloud Apps
02-04-2024
Solved

looking to create a custom Dashboard filter from a result from another widget (Live Data Model)

Dear Sisense Community, I am looking to see if there is a way through scripting that I can use the values from a Pivot table (one column of text data) to create a custom (Advanced) filter for the Da...
  • rapidbisupport's avatar
    02-07-2024

    Hi ssoltz ,

    You could achieve this with a BloX rendering a button and a dashboard script that:

    • gets the results from the target pivot table (specified by target widget oid)
    • uses those results to add members to a filter (specified by target filter title)
    • and then refreshes the dashboard to view the new results.

    Please note that the solution below will only work with pivot result sets acting as filter members. It could be adapted for different source results - but won't work OOTB.

    BloX Script:

     

    {
        "style": "",
        "script": "",
        "title": "",
        "showCarousel": true,
        "body": [
            {
                "type": "TextBlock",
                "id": "",
                "class": "",
                "text": "<button id='filterButton'>Set Filter</button>"
            }
        ],
        "actions": []
    }
    

     

    Dashboard Script (change the result widget oid to the pivot table oid and target filter title to the title of the filter you want to change):

     

    const targetWidgetWithResultOid = '65c2d47b874ecd0042b02068'
    const targetFilterTitle = 'CountryName'
    
    dashboard.on('domready', () => {
        $('#filterButton').on('click', () => {
            const targetWidgetWithResult = prism.activeDashboard.widgets.$$widgets.find((w) => { return w.oid === targetWidgetWithResultOid })
            const targetWidgetResponse = targetWidgetWithResult.queryResult.loadService.data.data[0].data.map((r) => { return r.value })
            const targetFilter = prism.activeDashboard.filters.flatten().find((f) => { return f.jaql.title === targetFilterTitle })
    	delete targetFilter.jaql.filter.all
            targetFilter.jaql.filter.members = targetWidgetResponse
            prism.activeDashboard.refresh()
        })
    })

     

     Let me know how you go?

    Thanks,

    Daniel

    RAPID BI

    [email protected]

    RAPID BI - Sisense Professional Services | Implementations | Custom Add-ons