Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

Power BI Report Server - Refresh data on embedded report

Hi -

 

Below, we have figured out the javascript code that can be pasted into the console to get a PowerBI Report Server report to refresh the data only (i.e. clicking the refresh button) on a timer. We can get this to work whether you are on the regular screen of the report server report or with it in the embed view, but not when it is actually embedded.

 

The use case would be to provide "real-time" data using report server so that these reports could be kept open, refreshed, and the dropdown choices stay as the user selected. 

 

Does anyone know how to get this code below to work when embedding a report on a website on an internal network?

 

Thank you!

 

function refreshPowerBI() {

this.frames[0].postMessage({kind:"powerbi.reportServerHost.IToolbarActionMessage",button:"refresh"},"https://[our report server]:443")

}

 

if(window.autoRefreshInterval) { clearInterval(window.autoRefreshInterval); };

window.autoRefreshInterval = setInterval(refreshPowerBI, 60*1000)

10 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    <iframe style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden;" frameborder=0 id="iframe" src="http://your-url:8080/Reports/powerbi/your-report:embed=true">
    </iframe>
    <script>
    function refresh()
    {
    this.frames[0].frames[0].postMessage({kind:'powerbi.reportServerHost.IToolbarActionMessage',button:'refresh'},'*');
    }
    setInterval(refresh, 120000);
    </script>
    </html>

    • andyba's avatar
      andyba
      Regular Visitor

      Hi Vincentt,

       

      I'm trying to get this to work with the September 2021 release of the PBRS. However, I'm not able to get the report to refresh using the code as you've included in your example. I was very optimistic when I used the new Desktop for the Sept2021 PBRS that includes an automatic page refresh feature. However, it seems to only be valid for the Desktop and not when uploading to the PBRS. Unfortunately! And I do not understand why this feature is included only in the Desktop...

       

      But back to the case: On which versions and configurations did you get this to work?

      I'm very intersted learning how to come around this hurdle!

       

      Thanks,

      -A

  • Anonymous's avatar
    Anonymous
    Not applicable

    You'd need to inject the script onto the page and call the function. I was able to get this working by using an iframe to host the inject call. You can do this by placing a custom html page in the wwroot folder of report server and then embedding the report into that html page. A sample of the code I used is below.

     

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>page title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge;" />
    <base href="/">
    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="format-detection" content="telephone=no" />
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    var frame = '<iframe src="your report url" id ="powerbiframe" name="powerbiframe" onLoad="injectJS()" runat="server" height="100%" width="100%" frameborder="0"></iframe>';
    $("#framecontainer").append(frame);
    })

    </script>
    <script>
    function injectJS() {
    var iFrameHead = window.frames["powerbiframe"].document.getElementsByTagName("body")[0];
    var myscript = document.createElement('script');
    myscript.type = 'application/javascript';
    myscript.src='dashrefresh.js';  //save your powerbirefresh function to a .js file in the same location as your html file
    iFrameHead.appendChild(myscript);
    }
    </script>

    </head>
    <body>
    <div id="pbi-loading"></div>
    <div>
    <ui-view></ui-view>
    </div>
    <div id="reportcontainer" align="center">
    <div id="framecontainer"></div>
    </div>
    </body>
    </html>

     

    • MontherKH's avatar
      MontherKH
      Frequent Visitor

      Where/how do I find the wwwfolder you're talking about?

  • Hello, I am using this solution on the September 2021 release.
    So far it worked without any issues.
    This is the code I was using so far.
    
    <iframe marginwidth="0" marginheight="0" width="100%" height="100%" scrolling="yes" frameborder=0 id="iframe" src="http://rMyrapport?rs:embed= true">
    </iframe>
    <script>
    function shift()
    {
    this.frames[0].frames[0].postMessage({kind:'powerbi.reportServerHost.IToolbarActionMessage',button:'refresh'},'*');
    }
    setInterval(shift, 10000);
    </script>
    
    
    But we installed the May 2022 version.
    Since this update, this code no longer works.
    Do you know why and especially how to correct.