Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

getSlicerState throws an error - TypeError : slicer.getSlicerState is not a function

How can fix the error  : -  TypeError : slicer.getSlicerState is not a function , when trying to call the getSlicerState of the slicer API .

 

The following is the code: 

var embedContainer = $('#embedContainer')[0];

report = powerbi.get(embedContainer);

report.getPages()

    .then(function (pages) {

  var activePage = pages.filter(function (page) {
           return page.isActive;
        })[0];
     activePage.getVisuals()
         .then(function (visuals) {
            var slicer = visuals.filter(function (visual) {
      return visual.type == "slicer" && visual.title == "Region";
    })[0];
 
                slicer.getSlicerState()
                    .then(function (state) {
                        console.log(state);
                    })

                    .catch(function (errors) {
                        console.log(errors);
                    });
            })

            .catch(function (errors) {
                console.log(errors);
            });
    })

    .catch(function (errors) {
        console.log(errors);
    });

 

2 Replies

  • amshuste's avatar
    amshuste
    Power BI Team

    Please try to check if your filter is right and that the "slicer" var is populated.
    Make sure that the visual title is "Region" 

    visual.title == "Region"

    We recommend to filter according to the visual name which is a unique identifier.

    If the visual is filtered right, and you still get this error, please try to update your JavaScript SDK version.

  • dax's avatar
    dax
    Community Support

    Hi Anonymous , 

    I am not professional in javascript, so I suggest you could create a support ticket (https://powerbi.microsoft.com/en-us/support/) for more suggestions.

    Best Regards,
    Zoe Zhi

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