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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
darthbob88
New Member

SetSlicerState throws Strange Error

I'm still trying to set up a minimal repro, but- When I try to set a slicerState on an embedded PowerBI report, using the below code, I get the below error. So far as I can tell, nothing of mine calls that code, and the catch blocks don't fire. This is just appearing from the aether. What, if anything, can I do about this, and where should I start troubleshooting? I've tried myself, but it's a minified file, so the undefined variable is just called `n`, and it's in an anonymous function inside another function just called `e`. Troubleshooting minified code has got to be one of the circles of Hell.

 
 const filter = {
      '$schema': 'http://powerbi.com/product/schema#basic',
      'target': {
        'table': 'Main_chart',
        'column': 'Date'
      },
      'filterType': 1,
      'operator': 'In',
      'values': ['2019-01-18T08:00:00.000Z']
    };
    this.component.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 visual = visuals.filter(item => item.type === 'slicer')[0];

            visual.setSlicerState(filter)
              .then(function () {
                console.log(`Filter was set for "Category Breakdown" table.${filter}`);
              })
              .catch(function (errors) {
                console.log(`Unable to set filter ${JSON.stringify(filter)}: ${JSON.stringify(errors)}`);
                visual.setSlicerState(filter)
              });
          })
          .catch(function (errors) {
            console.log(`Unable to get visual: ${errors}`);
          });
      })
      .catch(function (errors) {
        console.log(`Unable to get page: ${errors}`);
      });
 

 

Capture.PNG

1 ACCEPTED SOLUTION

Hi,

 

Try this trick, may be it will help.

 

Kind Regards,

 

Evgenii Elkin,
Software Engineer
Microsoft Power BI Custom Visuals
pbicvsupport@microsoft.com

View solution in original post

4 REPLIES 4
v-evelk
Microsoft Employee
Microsoft Employee

Hello,

 

Because I don't see any information is logged into console before the error happens and I see that the error is related with "length" I can propose that the error happens before log messages and it is probably somewhere here

 

 // Retrieve the wanted visual.
 var visual = visuals.filter(item => item.type === 'slicer')[0];

But I am not sure, please check this moment.

 

Kind Regards,

 

Evgenii Elkin,
Software Engineer
Microsoft Power BI Custom Visuals
pbicvsupport@microsoft.com

 

Hey Evgenii, thanks for the response. That's not it. That code does get the right slicer, and if I step into visual.setSlicerState(filter) it seems to work well there, but a breakpoint on the throw doesn't catch anything.

 

VisualDescriptor.prototype.setSlicerState = function (state) {
return this.page.report.service.hpm.put("/report/pages/" + this.page.name + "/visuals/" + this.name + "/slicer", state, { uid: this.page.report.config.uniqueId }, this.page.report.iframe.contentWindow)
.catch(function (response) {
throw response.body;
});
};

 

 

I've moved back to using just a filter as a parameter rather than the slicer here, so this isn't a priority, but it's still baffling.

Hi,

 

Try this trick, may be it will help.

 

Kind Regards,

 

Evgenii Elkin,
Software Engineer
Microsoft Power BI Custom Visuals
pbicvsupport@microsoft.com

I think it might work, but I'd have to put the extra catch in powerbi.js, which is a library that I don't own. I'll mark that as a tentative solution and move on elsewhere.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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