Skip to content

Instantly share code, notes, and snippets.

@patrickjquinn
Last active January 30, 2019 14:56
Show Gist options
  • Save patrickjquinn/92f56f0ec893d467b678ac30149cdc1e to your computer and use it in GitHub Desktop.
Save patrickjquinn/92f56f0ec893d467b678ac30149cdc1e to your computer and use it in GitHub Desktop.
function chartSelected() {
let dataSelect = Form1.chartsSegment.selectedRowItems[0];
getPowerBIIframe(dataSelect.Id);
}
function getPowerBIIframe(reportid){
let serviceName = "PowerBIServices";
let integrationClient = KNYMobileFabric.getIntegrationService(serviceName);
operationName = "getReportEmbed";
data= {"key": CLIENT_SECRET,"report": reportid};
headers= {};
integrationClient.invokeOperation(operationName, headers, data, operationSuccess, operationFailure);
Form1.chartsSegment.setVisibility(false);
function operationSuccess(res){
// Form1.brw1.htmlString = '<html><body><iframe frameborder="0" style="width:100%; height:100%;" src="'+res.EmbedUrl+'"></iframe></body></html>';
let contentString = `<html><body><div id="reportContainer" style="height:100%; width:100%"></div>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/powerbi-client@2.6.0/dist/powerbi.min.js"></script>
<script>
$(document).ready(function () {
debugger
var accessToken = "<at>"
var embedUrl = "<embed>"
var models = window['powerbi-client'].models;
var config = {
type: 'report',
accessToken: accessToken,
tokenType: models.TokenType.Embed,
embedUrl: embedUrl,
id: '<reportid>',
settings: {
filterPaneEnabled: false,
navContentPaneEnabled: true
}
};
var reportContainer = document.getElementById('reportContainer');
// Embed the report and display it within the div container.
var report = powerbi.embed(reportContainer, config);
// 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", function () {
});
report.on("error", function (event) {
if (event.detail && event.detail.message) {
alert(event.detail.message);
}
return;
});
})
</script></body></html>`;
contentString = contentString.replace('<at>',res.AccessToken);
contentString = contentString.replace('<embed>',res.EmbedUrl);
contentString = contentString.replace('<reportid>',res.ReportId);
Form1.brw1.htmlString = contentString;
Form1.brw1.setVisibility(true);
// callback(contentString)
}
function operationFailure(res){
alert('An error occured');
Form1.chartsSegment.setVisibility(true);
}
}
function getPowerBIReports () {
Form1.brw1.setVisibility(false);
Form1.chartsSegment.setVisibility(true);
let serviceName = "PowerBIServices";
let integrationClient = KNYMobileFabric.getIntegrationService(serviceName);
operationName = "getReports";
data= {"key": CLIENT_SECRET};
headers= {};
integrationClient.invokeOperation(operationName, headers, data, operationSuccess, operationFailure);
function operationSuccess(res){
powerBIReports = res.Items;
// Form1.chartsSegment.widgetDataMap = {ProductName:"Name",ProductThumb:"ThumbnailImageUrl"};
Form1.chartsSegment.setData(powerBIReports);
// getPowerBIIframe(powerBIReports[0].Id )
}
function operationFailure(res){
alert(JSON.stringify(res));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment