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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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)

4 REPLIES 4
Nicolas687
New Member

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.
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>

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
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>

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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