Home
Analytics
How would I be able to dynamically include Javascript files in a report?
mkdz
<p>Is this possible? Let's say I have two JS files, <strong>one.js</strong> and <strong>two.js</strong>. Is there a way in the report to load <strong>one.js</strong> in certain situations and <strong>two.js</strong> in others? If so, how? Thanks!</p>
Find more posts tagged with
Comments
mkdz
<p>I've found this from Google cache:</p><p> </p><p><a data-ipb='nomediaparse' href='
https://webcache.googleusercontent.com/search?q=cache:DYo_G4JiRK8J:developer.actuate.com/community/devshare/_/designing-birt-reports/1576-dynamic-javascript-loader/+&cd=2&hl=en&ct=clnk&gl=us'>https://webcache.googleusercontent.com/search?q=cache:DYo_G4JiRK8J:developer.actuate.com/community/devshare/_/designing-birt-reports/1576-dynamic-javascript-loader/+&cd=2&hl=en&ct=clnk&gl=us</a></p><p> </p><p>The
non-cache link redirects to the devshare and the resource download link is a dead link. Anyone know where I can get this? Thanks!</p>
donino
<p>Hi, </p><p> </p><p>Assuming you make use of birt 4.3.x here is what i do to achieve this:</p><p> </p><p>- Include 2 text HTMLelements in the report, let's call them "textOne" & "textTwo"</p><p>- in textOne: </p><pre class="_prettyXprint"><script> head.js("<yourURL>/one.js",function(){console.log("one.js is loaded")})</script></script></pre><p>- in textTwo: </p><pre class="_prettyXprint"><script> head.js("<yourURL>/two.js",function(){console.log("two.js is loaded")})</script></pre><p>- Other html text elements of the report can do some stuff with the loaded javascript framework with:</p><pre class="_prettyXprint"><script> head.ready(function(){ //do javascript stuff here });</script></pre><p>Then the finishing touch to this, we make use of the "visibility" property of each text element to show / hide as we need with a dynamic expression, most of the time an expression based on a report parameter. By contrast with "display" property, the "visibility" property actually removes items from the final rendering.</p><p> </p><p>I hope it will help.</p>
mkdz
<p>Thanks! SO I have gotten this to work. I can use HTML Text Elements display stuff based on which JS file I have loaded. However, I'm getting errors when I try to use the loaded JS functions in Dynamic Text elements. Do you know how to get those working? Thanks!</p>
mkdz
<p>I have my HTML Text Elements set up and the visibility set the way I want it. However, when I try and call my JS function in a Dynamic Text element, this is the error I'm getting right now:</p><p> </p><p><img src='
https://i.imgur.com/KGrKKap.png'
alt='Posted Image' class='bbc_img' /></p>
donino
<p>Javascript functions loaded using "head.js" can only be accessed through HTML text elements, wrapped in a "<script>" tag. However may be there is a confusion: with BIRT there are two distinct types of js files, they have the same extension but use cases are completely different. </p><ul class='bbc'><li>Server-side javascript ("Rhino" scripts)<ul class='bbc'><li>Executed on server</li><li>Can be used in all expressions of BIRT elements, such dynamic texts</li><li>Usually attached as a JS resource of a report or a report library</li><li>Examples: DaVinci charts, custom functions we want to share across reports etc.</li></ul></li><li>Client-side javascript<ul class='bbc'><li>Executed on web browsers</li><li>Can <strong>only </strong>be used in HTML text elements, wrapped in a script tag</li><li>Usually loaded through head.js</li><li>Available in <strong>HTML format only</strong></li><li>Allow to add interactive features in reports</li><li>Examples: embed Google maps, D3 charts, Google Visualization etc.</li></ul></li></ul><p> </p><p>I assumed you were talking about client-side javascripts, may be i was wrong? What do those js files contain?</p>
mkdz
<p>I am trying to load server side scripts dynamically since I use those JS functions in dynamic text elements.</p>