Embedding javascript

2
Hi, Sometimes it is useful to embed 3rd party functionality and packages. I would like to know how I should do that in a Mendix easy and friendly way. How should I embed this example, from this page: <script src="~/scripts/powerbi.js"></script> <div id="reportContainer"></div> <script> // Read embed application token from Model var accessToken = "@Model.EmbedToken.Token"; // Read embed URL from Model var embedUrl = "@Html.Raw(Model.EmbedUrl)"; // Read report Id from Model var embedReportId = "@Model.Id"; // Get models. models contains enums that can be used. var models = window['powerbi-client'].models; // Embed configuration used to describe what and how to embed. // This object is used when calling powerbi.embed. // This also includes settings and options such as filters. // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details. var config = { type: 'report', tokenType: models.TokenType.Embed, accessToken: accessToken, embedUrl: embedUrl, id: embedReportId, permissions: models.Permissions.All, settings: { filterPaneEnabled: true, navContentPaneEnabled: true } }; // Get a reference to the embedded report HTML element var reportContainer = $('#reportContainer')[0]; // Embed the report and display it within the div container. var report = powerbi.embed(reportContainer, config); </script> Using the JavaScript Snippet widget I can include the big script snippet but how do I associate the source part, src="~/scripts/powerbi.js", with that snippet? Is there another way of doing it? Kind regards Johan
asked
2 answers
0

Hello Johan,

You can add external js file in index.html file which located in theme folder.

 

answered
1

If you want to load the required script dynamically (not with each page) you can load it as dojo module with require function call on start of your js snippet code and place your js code in the callback function. Something like this:

 

require([“./path_to_the_source_file.js”], function(){

// js code

});

first parameter of require function is array, in case several files/modules are needed.

answered