Skip to content

Instantly share code, notes, and snippets.

@krishnaanaril
Created October 5, 2018 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishnaanaril/398f8e51136e649bf35e41baf8367efe to your computer and use it in GitHub Desktop.
Save krishnaanaril/398f8e51136e649bf35e41baf8367efe to your computer and use it in GitHub Desktop.
Embed Power BI reports for organization
getToken() {
this.adalSrv.context.acquireToken(environment.powerBIEndpoint, (error, token) => {
if (error || !token) {
// TODO: Handle error obtaining access token
console.error('ERROR:\n\n' + error);
return;
}
//Get available reports in the group
this.adalSrv.getReportsInGroup(environment.groupId).subscribe(res=>{
// select the first report among it.
this.getReport(res["value"][0]["id"], res["value"][0]["embedUrl"]);
});
});
}
getReport(id: string, embedUrl: string) {
// get token
// this.getToken();
var embedConfiguration = {
type: 'report',
id: id,
embedUrl: embedUrl,
tokenType: pbi.models.TokenType.Aad,
accessToken: this.adalSrv.context.getCachedToken(environment.powerBIEndpoint)
};
// Grab the reference to the div HTML element that will host the report.
const reportsContainer = <HTMLElement>document.getElementById(
'embedReport'
);
const report = this.powerbi.embed(
reportsContainer,
embedConfiguration
);
// Report.off removes a given event handler if it exists.
report.off('loaded');
// Report.on will add an event handler which prints to Log window.
report.on('loaded', (event) => {
console.log('report loaded...');
})
report.off('pageChanged');
report.on('pageChanged', e => {
console.log(e);
});
// Add a listener to 'error' events
report.on('error', (errorObject) => {
console.log(errorObject);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment