Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
FrançoisD
Regular Visitor

I can't get the "single selection required" real value of a slicer with the client API

Hello,

 

I have a report with a categorical slicer. This slicer has "single select" checked and renders as a "one selection" visual:

 

FranoisD_0-1718781081297.pngFranoisD_1-1718781093662.png

 

However, when I use the client API in embed mode, when I get this slicer and then run `const state = await slicer.getState()`

the `state.filters[0].requireSingleSelection` is always set to false whatever the check status on my report.

Is it a known issue or is it because I get the wrong attribute?

 

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @FrançoisD ,

Please review the following links, hope they can help get the expected result...

Get slicer state

Slicers · microsoft/PowerBI-JavaScript Wiki · GitHub

let state = await visual.getSlicerState();
// Get the list of visuals from the report
report.getPages()
    .then(function(pages) {
        return pages[0].getVisuals();
    })
    .then(function(visuals) {
        // Find the slicer visual by name or other properties
        let slicer = visuals.find(function(visual) {
            return visual.type === 'slicer' && visual.name === 'SlicerVisualName';
        });

        // Get the state of the slicer
        return slicer.getSlicerState();
    })
    .then(function(slicerState) {
        // Access the selected value
        let selectedValue = slicerState.targets[0].target;
        console.log('Selected Value:', selectedValue);
    })
    .catch(function(errors) {
        console.error(errors);
    });

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello,

Thanks for your reply but, it does not answer my question at all.

I am already using the getSlicerState function and I can already get the selected value and even set it.

My issue is that I cannot programmatically make the difference between a slicer that only accept one selected value and a slicer that accept many because the "requireSingleSelection" boolean is always set to "false" in the state.filters attribute.

Regards

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.