Menu Chiudi
View Categories

Creating Custom Reports

Data Crow allows users to add their own reports or to modify the existing reports.
The reports are created with the Jaspersoft Studio software. This software is free for download.

Prerequisites #

  • You need Jaspersoft Studio 7 or newer. Download it from: https://community.jaspersoft.com/project/jaspersoft-studio. Report files saved with version 6 or older cannot be compiled by Data Crow.
  • You need Data Crow version 5.3 or higher.
  • To add a report to Data Crow you need to be an administrator (in a stand alone installation you always are).

The Report Process
#

Report Templates

Data Crow uses reports of Jaspersoft. A report is made in Jaspersoft Studio as a .jrxml file. The reports are managed and run by the server (a stand alone installation is its own server).

An administrator adds a report with the Manage Reports tab of the report window of the module (see Reporting): select your .jrxml file and the server compiles it. To test a change, add the file again; Data Crow asks whether to replace the report with the same name. Reports are kept per module, and the reports which come with Data Crow are put back when the server starts.

To change a report which comes with Data Crow, copy its .jrxml file from the reports folder of the installation, change the copy and add it under another name.

Report Creation

When you run a report from Data Crow (Report > Create Report) Data Crow does three things:

  • Data Crow creates an XML export of the selected items.
  • Data Crow fills the .jasper report file with the XML data.
  • And as a last step the filled report is saved in the selected target format (PDF, HTML, RTF, DOCX or XLSX).

The most important thing to note is that Data Crow uses XML extracts for creating the reports rather than accessing the database directly. We will use the XML in the next chapter to design a new (or modify an existing) report.

The pictures of the items are included automatically, scaled to at most 200 x 200 pixels. An HTML report consists of an HTML file with the pictures in a folder next to it.

Creating a New Report
#

Let’s design a new report! We’ll need a XML file holding Data Crow items (as a source) to create and design a report in Jaspersoft.

Create an XML export

First, we need to have an example XML file so we can use this to design our report.

  1. Start Data Crow.
  2. Select the module for which you want to create a report.
  3. Select one or more items in the view, right-click and select Item Export Wizard (or use File > Export > Item Export Wizard to export all items of a module).
  4. Select XML export and press Next.
  5. Select the target file, check Include Pictures and press Next.
  6. Leave all fields selected and press Next.
  7. The export is created. Press Finish.

The wizard is described on the Item Import & Export page.

Note that we will only use this XML as an example for creating our new report. Data Crow will create the XML extract automatically when you run the report from within Data Crow (Report > Create Report). It’s important that you selected items which hold the most information as well as a couple of items with very limited information. This is always good for testing the report.

JasperSoft Studio #

Next, start Jaspersoft Studio. On a first start you will be asked to select a workspace location. Pick any location that you want. Once started close out of any of the welcome screens until you are in the actual work area.

First thing we need to do is to set up the XML file we exported as a Data Adapter. Data adapters are used to fill reports with data. Select the Repository Explorer tab and right-click on the Data Adapters. From the right-click menu, select Create Data Adapter.


Select XML Document;

Press Next to further configure the XML data adapter.
Fill at least the following fields (other fields are optional and explained in the documentation of Jaspersoft Studio):
  • Name: enter any name you want, recognizable to yourself.
  • File: select the XML export as created by Data Crow. In my case this was text.xml. Note that for running the report by Data Crow this file will not be used, this is only for designing the report.
  • Tick the “Use the report Xpath expression when filling the report”. This is very important as you otherwise will end up with an empty report for your test runs.

Press Test to test your set up.
Press Finish to end the data adapter creation.

Create a Blank report

So we now have an XML file which is set up as a data adapter in your Jaspersoft environment. Next logical step is to create a new report, using the data adapter as input.

Navigate to the Project Explorer. By default this will hold a project named MyReports. You are free to use any other project name you want to, it’s not important for the Data Crow reports.

Right-click on the project and select New, Jasper Report.

Now you can select a Report Template. For Data Crow reports you can choose any report template you want. For more details on these templates I refer you to the Jaspersoft Studio documentation. For now, I’ll choose the Blank A4 template. Press Next.

Next Jaspersoft Studio will ask you to name the report so that it can be saved into your project.
Give it a name that will make sense; the name of the report file is shown in the Data Crow report selection. For this example I’ll call this report Test. Press Next to continue to the next step.

Now, we are in step where we will link the data adapter to the report. This will allow the report to find the fields available and fill them with information when running the report.

  • Select the Data Adapter from the dropdown. In my case it is called Test XML.
  • In the field below the structure of the XML file is shown. Now we need to define how Jaspersoft Studio has to use the XML information. For
    the example you can see I have exported software items. A total number 4 items are present, each item is a software element within software-items (the example pictures show the older name software-item). Looking at a single item, we can see all the fields:
  • Double click on the node that holds all the fields. This makes all items available in the report.

    Note that for XML exports from other modules you will see for example Movie, Book, Music Album, etcetera instead of software. The steps to follow are exactly the same. Press Next.
  • In the next step you’ll have to choose which fields to include in the report. If no fields are listed or this step is skipped it means you have made a mistake in the previous step. I have selected all fields by pressing on the >> button. I recommend adding all fields as this gives the most flexibility.
  • At this point you can choose to Finish the wizard. Alternatively you can continue by pressing Next which brings you to the option to set up grouping. Grouping however is not covered in this guide; I’ll have to refer you to the Jaspersoft Studio documentation. It is supported by Data Crow, so no worries there.

Now we have a blank report with a configured data adapter.

Design tips & Tricks #

For full documentation on how to design you report in the Jaspersoft Studio software you are referred to the documentation available from the Jaspersoft site:
https://community.jaspersoft.com/project/jaspersoft-studio

There are manuals as well as Wikis available.

To help you get started, I’ll explain some of the basics.

Report Layout

In the centre of the screen you’ll find the report itself. You can see the various sections, such as Title, Page Header and so on. You can resize the sections with the mouse.

These sections can be removed (or added) from within the Outline section:

 

Adding Fields

All the fields as part of the XML data adapter can be found in the outline section of the workspace. From here you can drag and drop fields onto the report:

Multi-reference fields

A field which refers to other items, such as genres, is written twice: genres-items holds the individual items and genres-items-list holds their names, separated by commas. Use the -items-list field to show the names. To iterate over the individual items instead you have to add a List element.

Image fields (pictures)

Optionally you can also choose to first add a specific element onto the report and then specify which value to use. Let’s add an image for example. On the right hand side of the screen you’ll find a section called palette. Here you find all field types available. Select Image and drag and drop this onto the report.

In the dialog that appears, select Custom expression. This enables the Options field.

Press the button.

By
default the Fields are all shown. Select the picture field you want to add and double-click it. The main picture is picture-01, the other pictures are picture-02, picture-03 and so on (the example pictures show the older name picture-front).

Empty field content

Jaspersoft will print NULL in case the field is empty. I prefer to have the field show nothing in case a field is empty. This can be done though the properties of the field. Select the field by clicking on it in the Main Report view. In the example below I have selected the Title field.

Let’s change the properties of this field. Click on the field (as done in the above example). Now navigate to the Properties section.
Select Text Field.

Check the box Stretch With Overflow. It does just that; whenever the content is too large, the field will be stretched, making all of its content visible.

Check Blank When Null to show nothing when the field is empty.

Field Positioning

Any field added to the report is automatically aligned, related to the top. This can be quite useful if you want your field to remain at the same place at all times; when the report is stretched the position of the field remain at the same relative distance of the top of the report section.

This problematic when you have placed the field below a text field (see above) which Stretches With Overflow.
The field will be placed on top of the stretched field as it positions itself relative to the top of the report section, not relative to the field above.

To accommodate for this set this field to Position Type Float instead:

Other Fields

There are many field types available to display the source content (the XML information). There are also fields available such as the page number. These fields can be found in the Palette section:

Report Preview #

At any time during the design process you can do a preview of the report. Click on the preview button, as shown below:

By doing a preview you get to see what the report looks like to the end user. Also, the report is checked for errors.

Compiling and Deploying the Report #

When the report is ready, save the report file. Data Crow needs the .jrxml file only: the server compiles it, so you do not have to build it in Jaspersoft Studio or copy files yourself.

  1. Select the module in Data Crow and open Report > Create Report.
  2. Open the Manage Reports tab (administrators only).
  3. Use the button to add a report and select your .jrxml file. A report with the same name is replaced after you confirm. When the report cannot be compiled the reason is shown and nothing changes.

The report window: Manage Reports

The report is now available right away; Data Crow does not need to be restarted. On the Create Report tab select the report, the report format and the target file, and press Run. See Reporting.

The report window: Create Report