Forum Discussion

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

Excluding from an existing Dashboard filter using BLOX

Hello,

I had an earlier challenge which was solved by Daniel (@rapidbisupport). Thank you!

Now, I'm hoping to take this one step further. After the Dashboard filter has been created, I'd like to create another BLOX button to remove specific filter entries from the list (either remove from the include or exclude) using a similar method as previous.

Here is the link to the last request / post:

link to post

Thank you in advance!

  • Hi ssoltz ,

    You should be able to place the code directly under the initial code on the dashboard script.

    This should enroll both methods to the dashboards 'domready' event - you can have multiple 'dashboard.on('domready', ()=> .....) and they won't 'overwrite each other'.

    Just need to make sure none of the names assignments at the top are named the same.

    Let me know how you go?

    Thanks,

    Daniel

    RAPID BI

    [email protected]

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

  • Thanks for the Chat today ssoltz ! Was great to jump on a call and I hope you got some value out of it.

    As discussed, looks like I missed a bracket in the original response, causing your adapted script to fail.

    The changes required are as below:

    const targetWidgetWithExclusionsResultOid = '65c2d47b874ecd0042b02068'
    const targetFilterTitle = 'CountryName'
    
    dashboard.on('domready', () => {
        $('#removeExclusionsFilterButton').on('click', () => {
            const targetWidgetWithExclusionsResult = prism.activeDashboard.widgets.$$widgets.find((w) => { return w.oid === targetWidgetWithExclusionsResultOid })
            const targetWidgetResponse = targetWidgetWithExclusionsResult.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 = targetFilter.jaql.filter.members.filter((i) => { return !targetWidgetResponse.includes(i) } ) // MISSING BRACKET PREVIOUSLY
            prism.activeDashboard.refresh()
        })
    })
    

    Don't hesitate to reach out if we can help with anything else!

    Thanks,

    Daniel

    RAPID BI

    [email protected]

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

     

8 Replies

  • Hi ssoltz ,

    You should be able to place the code directly under the initial code on the dashboard script.

    This should enroll both methods to the dashboards 'domready' event - you can have multiple 'dashboard.on('domready', ()=> .....) and they won't 'overwrite each other'.

    Just need to make sure none of the names assignments at the top are named the same.

    Let me know how you go?

    Thanks,

    Daniel

    RAPID BI

    [email protected]

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

  • Hi ssoltz ,

    All possible - what do you want to remove from the filters?

    "remove specific filter entries from the list"

    I mean you could set up a second BloX that looks like:

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

    and then remove members from the filter related to another 'target pivot with a list of exceptions' like this in the widget script:

    const targetWidgetWithExclusionsResultOid = '65c2d47b874ecd0042b02068'
    const targetFilterTitle = 'CountryName'
    
    dashboard.on('domready', () => {
        $('#removeExclusionsFilterButton').on('click', () => {
            const targetWidgetWithExclusionsResult = prism.activeDashboard.widgets.$$widgets.find((w) => { return w.oid === targetWidgetWithExclusionsResultOid })
            const targetWidgetResponse = targetWidgetWithExclusionsResult.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 = targetFilter.jaql.filter.members.filter((i) => { return !targetWidgetResponse.includes(i) } 
            prism.activeDashboard.refresh()
        })
    })
    

    But difficult to provide more info without more specifics. From memory you had a video the first time that outlined the requirement really well - otherwise happy to jump on with Sisense Services | Free 30-Minute Sisense Consultation (rapidbi.com.au).

    Let me know how you go?

    Thanks,

    Daniel

    RAPID BI

    [email protected]

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

     

    • ssoltz's avatar
      ssoltz
      Cloud Apps

      Daniel,

      I am working on this currently. I will make a video shortly if I cannot get this to work (no luck so far).

      So, my confusion currently is that the original solution you created for me was embedding the script in the Dashboard script not a widget script as you state above. So, I'm either trying to use this as a widget script (in this case, which widget...the new button widget? This is not working)...or combining this new script with the old Dashboard script (this is not working yet as I do not know the syntax).

      Thank you!

    • ssoltz's avatar
      ssoltz
      Cloud Apps

      Daniel rapidbisupport ,

      Here is the new video:

      Video

      I have a feeling your new solution paired with the old one will work. My biggest question is where to put the script. The old one was placed as a Dashboard script. So, I either have to merge old code with new there or understand which widget to add the script to.

      By the way, here is my hacked version of your code to create the same filtered records on equivalent Dashboard filters from two different datasets:

      const targetWidgetWithResultOid = '65c79382dbb6a200328554a3'
      const targetFilterTitle = 'CAD Inc Num Filter'
      const targetFilterTitle1 = 'EMS Inc Num Filter'
      
      
      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 })
      		const targetFilter1 = prism.activeDashboard.filters.flatten().find((f) => { return f.jaql.title === targetFilterTitle1 })
      	delete targetFilter.jaql.filter.all
              targetFilter.jaql.filter.members = targetWidgetResponse
              prism.activeDashboard.refresh()
      	delete targetFilter1.jaql.filter.all
              targetFilter1.jaql.filter.members = targetWidgetResponse
              prism.activeDashboard.refresh()
      
          })
      })

      Thank you AGAIN for your assistance! 

      • rapidbisupport's avatar
        rapidbisupport
        Data Pipeline

        Thanks for the Chat today ssoltz ! Was great to jump on a call and I hope you got some value out of it.

        As discussed, looks like I missed a bracket in the original response, causing your adapted script to fail.

        The changes required are as below:

        const targetWidgetWithExclusionsResultOid = '65c2d47b874ecd0042b02068'
        const targetFilterTitle = 'CountryName'
        
        dashboard.on('domready', () => {
            $('#removeExclusionsFilterButton').on('click', () => {
                const targetWidgetWithExclusionsResult = prism.activeDashboard.widgets.$$widgets.find((w) => { return w.oid === targetWidgetWithExclusionsResultOid })
                const targetWidgetResponse = targetWidgetWithExclusionsResult.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 = targetFilter.jaql.filter.members.filter((i) => { return !targetWidgetResponse.includes(i) } ) // MISSING BRACKET PREVIOUSLY
                prism.activeDashboard.refresh()
            })
        })
        

        Don't hesitate to reach out if we can help with anything else!

        Thanks,

        Daniel

        RAPID BI

        [email protected]

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

         

  • Hello ssoltz ,

    I wanted to follow up to see if the solution offered by rapidbisupport worked for you.

    If so, please click the 'Accept as Solution' button so that other users with the same questions can find the answer faster. If not, please let us know so that we can continue to help.

    Thank you.