cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
greatzt Regular Visitor
Regular Visitor

slicer.setSlicerState not working and got "TypeError: slicer.setSlicerState is not a function"

I tried using the slicer.setSlicerState PowerBI JS function and got error "TypeError: slicer.setSlicerState is not a function".  I tried this in the in App Owns Data sample , which is a ASP.Net MVC .  The following is the function I used.  The slicer visual is found but slicer.setSlicerState will generate error.  I have no issues  on only applying page level filters by using  activePage.setFilters([filter]), in which filter is same.  Any suggestion? Thanks!

 


function ApplySlicer() {
const filter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "Client_Market",
column: "Customer_Market_Name"
},
operator: "In",
values: ["Idaho Market"],
};

// Get a reference to the embedded report HTML element
var embedContainer = $('#reportContainer')[0];

// Get a reference to the embedded report.
var report = powerbi.get(embedContainer);

// Retrieve the page collection and get the visuals for the first page.
report.getPages()
.then(function (pages) {
// Retrieve active page.
var activePage = pages.filter(function (page) {
return page.isActive;
})[0];

activePage.getVisuals()
.then(function (visuals) {
// Retrieve the wanted visual.
var slicer = visuals.filter(function (visual) {
console.log("sliler is founcd")
return visual.type == "slicer" && visual.name == "c5003ae82a250a09e010";
})[0];

// Set the slicer state which contains the slicer filters.
slicer.setSlicerState({ filters: [filter] })
.then(function () {
console.log("Market slicer was set.");
})
.catch(function (errors) {
console.log(errors);
});
})
.catch(function (errors) {
console.log(errors);
});
})
.catch(function (errors) {
console.log(errors);
})

}

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Users Online
Currently online: 485 members 4,403 guests
Please welcome our newest community members: