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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
powerbi_noob
New Member

Problem calling functions on Report object

Hi, I'm able to display my report on my web application, but after that I can't do anything with the Report object returned by powerbi.embed(...). What happens is that anytime I call a function on the object (setFilters, for example), the Promise never enters the "then" nor "catch" part of my code. It's as if the Promise remained pending forever.

On firefox I get these errors for each function I try to call, which I assume are relevant:

 

Here is the relevant sections of my code:

 

<script src="js/powerbi-client/dist/powerbi.js"></script>
<script>
    var models = window['powerbi-client'].models;
    var permissions = models.Permissions.Read;

    const filter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "Driver",
            column: "DriverID"
        },
        operator: "In",
        values: [<%= driver_id %>]
    };

    var config = {
        type: 'report',
        tokenType: models.TokenType.Embed,
        accessToken: '<%= token %>',
        embedUrl: embed_url,
        id: config_id,
        permissions: permissions,
        filters: [filter],
        settings: {
            filterPaneEnabled: false,
            navContentPaneEnabled: false
        }
    };

    var embedContainer = document.getElementById('embedContainer');
    var report = powerbi.embed(embedContainer, config);

    report.on("loaded", function (e) {
        alert('this is successfully called')
    })

    report.setFilters([filter]).then(function (result) {
        alert("never called 1");
    }).catch(function (errors) {
        alert("never called 2");
    });

    report.getPages().then(function (pages) {
        alert('never called 3')
    }).catch(function (errors) {
        alert('never called 4')
    });

</script>

 

Thanks for your help!

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee

@powerbi_noob

You shall bind those functions in the "loaded" event, try below sample which works in my test. My understanding is that, before "loaded", the report object is not valid.

 

 report.on('loaded', event => {
 
  report.setFilters([Filter2]).then(function (result) {
        alert("never called 1");
    }).catch(function (errors) {
        alert("never called 2");
    });

    report.getPages().then(function (pages) {
        alert('never called 3')
    }).catch(function (errors) {
        alert('never called 4')
    });
 
 
});

When calling within report.on ('loaded'), i see that report.getPages() function is not available. 

while it is available when calling from outside and observerd that promise is always pending. 

 

var report = powerbi.load(embedContainer, config);

report.on('loaded', () => {

  report.getPages().then(function (pages) {
  // Retrieve first page.
  var firstPage = pages[0];
  firstPage.getVisuals().then(function (visuals) {
    console.log(visuals);
   });
});

});

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.