Home
Analytics
Using custom javascripts in BIRT reports
zomkar
Hi,
I want to know if custom javascript functions can be written in BIRT report. This is because, i have a scenario as follows:- (Closely related to drill down)
First a list of customers is displayed to the user. The customer names are hyperlinks. When user clicks on the one of the hyperlink, then, i want my custom javascript function (lets say drillThis();) to be executed. This function, will make AJAX request to another report of Orders pertaining to the customers(CUSTOMER ID will be passed in request parameters)
The report generated by the second report will be obtained from AJAX response, and the order list will be displayed inline with the customer link that was clicked, indicating to the user, the orders related to that specific customer.
Please let me know in case of any work arounds.
I tried, to create a hyperlink on TEXT element of the report, and on its onclick event i execute an alert(); The alert is displayed, but i don't know, if, a custom javascript function can be called, and where to declare the javascript function in the report?
Thanks and Regards
Omkar Patkar
Find more posts tagged with
Comments
CBR
Hi,<br />
<br />
BIRT JavaScript is not clientside JavaScript but serverside Javascript. So the name Javascript is totally misleading. Serverside JavaScript has nothing to do with client side javascript (the one running in your internet browser).<br />
Serverside Javascript is just another programming language that's compiled to java bytecode and that runs on the server when the report is executed.<br />
<br />
A workaround on how to use the browser javascript is to put your javascript code inside of text elements. So when the report is generated in HTML this raw javascript is added to the HTML page. See <a class='bbc_url' href='
http://www.birt-exchange.org/devshare/interactive-reporting/146-web-2-0-and-birt/#description'>Web
2.0 and BIRT - Tips & Tricks - BIRT Exchange</a> for a brief introduction. But i m nearly sure that you won't be happy to develop rich functionalities using this approach.<br />
<br />
hope this helps
zomkar
Hi CBR,
Thank you so much. I am using Eclipse and BIRT plugin available with Eclipse to learn BIRT. So when i run i my report, i am actually using ECLIPSE BIRT plugin.
Eclipse 3.2
BIRT 2.1
I tried inserting a Text element which is as follows: -
=========================================================
<script>
alert("WOW!");
function testFunc()
{
alert("Yipee! Javascript works!");
}
</script>
sample Text!
=========================================================
and to test this .... in the detail row element of table i inserted another Text element which will generate hyperlink, and on click of the hyperlink the above function will be called. The hyperlink text element is as follows: -
=========================================================
<A name="test"+<VALUE-OF>row["CUSTOMERNUMBER"]</VALUE-OF>) href="#" onclick="alert('Hi! '+<VALUE-OF>row["CUSTOMERNUMBER"]</VALUE-OF>);testFunc();">
Test Link
</A>
=========================================================
as you can see, i have also inserted an alert. When the report is generated. and when i click on the link, then alert is displayed and error is reported after that, saying "testFunc" is not defined.
When i opened the HTML source code of the generated report, then i realized, after generation of the report, the first text element containing the definition of the custome javascript function shown at the top was not generated.
What could be the problem?
Thanks and Regards
Omkar Patkar
zomkar
any idea guys ?