Last active
April 25, 2017 16:06
-
-
Save EliJDonahue/8da63b42a2ef08b4a9a2029b4870ade4 to your computer and use it in GitHub Desktop.
Sample code for an embedded Power BI report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div id="pbiContainer"></div> | |
| <script type="text/javascript"> | |
| // be sure to set the path for your Aras instance | |
| require(["http://localhost/innovatorserver/Client/customer/powerbi/scripts/powerbi.js"], | |
| function (pbi) { | |
| var innovator = aras.newIOMInnovator(); | |
| var item = "report"; // The type of Power BI element you are querying | |
| var itemName = "Product"; // The name of the element in Power BI you are querying | |
| // Call the PowerBI_GetItem server method that will get an access token | |
| // and then query the necessary information from Power BI needed to | |
| // embed the element into the HTML field | |
| var result = innovator.applyMethod( | |
| "PowerBI_GetItem", | |
| "<item>" + item + "</item><itemName>" + itemName + "</itemName>"); | |
| if (!result.isError()) { | |
| if (item == "dashboard") { | |
| var id = result.getItemByIndex(0).getProperty("id", ""); | |
| var name = result.getItemByIndex(0).getProperty("displayName", ""); | |
| var embedUrl = "https://app.powerbi.com/dashboardEmbed?dashboardId=" + id; | |
| var accessToken = result.getItemByIndex(0).getProperty("token", ""); | |
| if (id != "" && embedUrl != "" && accessToken != "") { | |
| embedConfiguration = { | |
| type: 'dashboard', | |
| accessToken: accessToken, | |
| id: id, | |
| embedUrl: embedUrl | |
| }; | |
| var pbiContainer = document.getElementById("pbiContainer"); | |
| // Use the Power BI module to embed the | |
| // Power BI element into the pbiContainer HTML field | |
| var powerbi = new pbi.service.Service( | |
| pbi.factories.hpmFactory, | |
| pbi.factories.wpmpFactory, | |
| pbi.factories.routerFactory); | |
| var db = powerbi.embed(pbiContainer, embedConfiguration); | |
| } | |
| } | |
| else if (item == "report") { | |
| var id = result.getItemByIndex(0).getProperty("id", ""); | |
| var name = result.getItemByIndex(0).getProperty("name", ""); | |
| var embedUrl = "https://app.powerbi.com/reportEmbed?reportId=" + id; | |
| var accessToken = result.getItemByIndex(0).getProperty("token", ""); | |
| if (id != "" && embedUrl != "" && accessToken != "") { | |
| var embedConfiguration = { | |
| type: 'report', | |
| accessToken: accessToken, | |
| id: id, | |
| embedUrl: embedUrl | |
| }; | |
| var pbiContainer = document.getElementById("pbiContainer"); | |
| // Use the Power BI module to embed the | |
| // Power BI element into the pbiContainer HTML field | |
| var powerbi = new pbi.service.Service( | |
| pbi.factories.hpmFactory, | |
| pbi.factories.wpmpFactory, | |
| pbi.factories.routerFactory); | |
| var db = powerbi.embed(pbiContainer, embedConfiguration); | |
| } | |
| } | |
| } | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment