Creating a BIRT report using a Scripted Data Source
TODO: This page was written during our first encounter with BIRT and needs updating. Although most information here is still valid, some parts have changed, such as the Javascript that retrieves option lists for input parameters. Also, we don't recommend using libraries, at least initially.
See the Flash Video on creating a Mifos report in BIRT to see how a report is designed.
- You may need to install Adobe Shockwave Player to view this file.
Create a library using Scripted Data Source
- New a library: Click File->New->New library, and then change the default library name to a user friendly name.
- New data sources using Scripted Data Source. New data source->select Scripted Data Source, and then change the default data source name. Verify that the Script Tab is selected and then write open and close methods which are displayed in the method drop down list.
- Write the open method
.. image:: birt.newDataSource.open.JPG
- Write the open method
Firstly we should register the Logger class. Then we create a reportsDataService object and initialize the login user. In the end, call the method enableThreadCacheForReports() to enable the thread cache for reports.
- Write the close method
.. image:: birt.newDataSource.close.jpg
Set object reportsDataService to null to release it. Then call the method disableThreadCacheForReports() to disable thread cache for reports.
- New data sets: click New data sets->change the default data set name >click next>add output columns->click finish. Verify that the Script Tab is selected and then write open, fetch and close methods which are displayed in the method drop down list.
- Define output columns
.. image:: birt.newDataSet.columns.jpg
- Define output columns
Add two output columns, one for String prdOfferingId and the other for String prdOfferingName in a loanOfferingBO object.
- Write the open method
.. image:: birt.newDataSet.open1.jpg
Initialize the Logger and log the request information. Get all the loan products and then save this record to reportContext and at the same time do logging in the Logger class. If more than one loan product is fetched, then the 2nd one, the "all loan products" is set as the default. Finally, set an iterator for the loan products collection.
- Write the fetch method
.. image:: birt.newDataSet.fetch.jpg
The fetch method is used to get the records from iterator to display in the two columns which have been designed in the Data Set.
- Write the close method
.. image:: birt.newDataSet.close.jpg
The close method is to set two objects (interator and loanProducts) to null to release them.
Create a BIRT report using a library
- Create report using your selected library. Open your selected library, Click File->New->New report, and then change the default report name to a user friendly name.
- Create the Data sources, Data sets, Report parameters and Master pages for created report.
.. image:: birt.report.data.create.use.library.JPG- Drag the Scripted Data Source from library into Data Sources folder of the created report.
- Drag the needed Data sets from library into Data Sets folder of created report.
- Drag the needed report parameters from library into report parameters folder for created report.
- Drag the pre-designed Master pages from library into the Master pages folder of created report, and delete unnecessary Master Page under the folder of created report.
- create report template. _ Select the Layout Tab->right click->Insert->Table. _ Define the layout Table according to the Mock report template. Change the table size as you wanted.
.. image:: birt.report.layout.table.JPG- Drag the output columns from Data Set to expected place in the template according to the Mock report template.
- Choose the Palette view and drag Text into the right place on the table, and input the expected text.
- Drag the Data into the right place on the table, and finish the Expression of Data.
.. image:: birt.report.template.data1.JPG.. image:: birt.report.data.experssion.JPG
Layout and format the report
- Edit the report template * Open the report which you want to edit, select layout Tab.
.. image:: birt.report.template.edit.JPG- Then you can edit the output columns, text, and data of the report template. _ Edit the output columns. You can drag the columns wherever you want in the table, and also can remove it (right click->delete). _ Edit text. Double click, and then input the text you wanted. * Edit Data. Double click, and then change the Expression of Data.