Skip to content


Include Jasperreports Activity in templates

With the JasperReports activity you can generate reports in pdf or docx format by using your process data. The report modeled in the Jaspersoft Studio (jrxml file) is supplied with data through this activity and converted into pdf or docx format. We currently only support to have the report before the activity. The configuration of the activity requires access to the report. As usual, the integration of the Activity in the process (node) is done by drag & drop.

Activitiy Configuration

Immediately afterwards the wizard opens in which you can configure the activity. First, under the Report source area, specify whether the report is to be embedded directly as a jrxml file or loaded from an URI. In the case of an URI, the specified target must be reachable from the process and during execution by the client. The embedded report template is gzipped and Base64-encoded.

The output format depends heavily on the content of the report, so you should consider your report when determining the output format. Otherwise a conversion can become complex, e.g. from html to Excel format or vice versa. You can select the desired format from the dropdown box as shown in the next image. The JasperReports activity can mainly render to docx and pdf. The output format can either be configured directly or via providing a file name for the output file. This must then have an appropriate file extension. If no output file name is provided, a random file name (using process instance data) will be used.

The report rendered by the JasperReports activity can either be stored as FileUDT to an output parameter and/or to the local file system. At least one output is required. For storing to a local file, an output directory is required.

JasperReports Parameters

Due to the complex relation between activity and report parameters, we currently only support to have the report before the activity. The activity needs to have access to the report. It reads the report and creates the appropriate activity input parameters. Every report parameters leads to a corresponding dual activity input parameters. Due to the duality, each input parameter may be replaced by a corresponding configuration value. This is done on the second page of the PnP wizard.

Most input parameters (generated for report parameters) and the configuration parameters (output file handling) are dual, i. e. they can be activity input parameters or activity configuration entries. The parameters that you define in this wizard as activity configuration and make assignments no longer have to be supplied differently. Parameters which have the property „Is For Prompting“ in Jaspersoft Studio are considered mandatory (they are prompted, so we consider them required). The parameters without "Is For Prompting" Flag are treated optional by us. Parameters which are null (for the activity), lead to the parameter having the defined default value from the report.

Parameter Mapping

On the next page Parameter Mapping you can check and confirm the automatic parameter mapping to data elements. And finally, the parameters in reports can be supplied by the process data.

Report parameters have Java classes as types. The mapping of these Java classes to the types of the (dual) activity input parameters is as follows:

Value Class AdeptDataType
java.lang.Boolean BOOLEAN
java.lang.Integer INTEGER
java.lang.Long INTEGER
java.lang.Short INTEGER
java.lang.Double FLOAT
java.lang.Float FLOAT
java.math.BigDecimal FLOAT
java.lang.String STRING
java.util.Date DATE
java.sql.Date DATE
java.sql.Time DATE
java.sql.Timestamp DATE URI URI
Value Class UDT Name Conversion application/json new JsonDataSource(udtValue.getValueAsStream())
org.json.JSONObject application/json new JSONObject(new JSONTokener(udtValue.getValueAsStream())) application/xml new JRXmlDataSource(udtValue.getValueAsStream())
de.aristaflow.adept2.extensions.datatypes.FileUDT File new FileUDT(udtValue)
java.awt.Image File ByteArrayInputStream(new FileUDT(udtValue).getData())
java.util.Collection List<USERDEFINED> new ListUdt(udtValue).getList()
java.util.Set List<USERDEFINED> new HashSet<Object>(new ListUdt(udtValue).getList())
java.util.List List<USERDEFINED> new ListUdt(udtValue).getList() List<USERDEFINED> new JRBeanCollectionDataSource(new ListUdt(udtValue).getList())
de.aristaflow.adept2.model.datamanagement.UDTValue * udtValue
<arbitraryClassName> <arbitraryClassName> ComponentObjectInputStream.fromInputStream(udtValue.getValueAsStream()); The class has to implement

PDF Font

JasperReports Activity provides „Noto Sans“ as font. You should use this in exactly this same notation; you may need to enter the name manually in the Jaspersoft Studio as shown in the next image. Then the rendered PDF-file is in Noto Sans font.

If another font should be used, you will have to work with font extensions.
Finally you have to publish the font to the server. The server must be able to display the desired font. Since this is not the case in servers without the graphical user interface, JasperReports needs a virtual display, e. g. Xvfb.

Example: Render PDF with JasperReports

In this example we only work with parameters in JasperReports. As already mentioned, the report must be completely modeled before it can be integrated into the activity. The report we created has the following parameters with Value Class as shown in the next image.
After the integrating the report into the JasperReports Activity the template looks like this:
To generate this process template, first, integrate the JasperReports Activity by dragging it to the desired area in the graph and configure it as shown above. At the end of the configuration you should see the automatically created parameters in the editor as shown in the last image.

Then you can assign suitable values to these parameters ​​in a process step Init in the Scripting Activity as shown below. Please pay particular attention to the assignments for the FileUDT's and Json-File.

import de.aristaflow.adept2.extensions.datatypes.FileUDT; $LogoImage = new FileUDT(new File("C:/.../af_logo.png")).getAsXML(); $FileUDT = new FileUDT(new File("C:/.../jasper.txt")).getAsXML(); $Item = "Smartphone"; $Description = "64 GB, A123 Gold"; $Amount = 344; $Total = 688; $Quantity = 2; $Json = ''' { "Customer": { "Name": "John Smith", "Adress": "30 Living Street, London", "Phone": "800-123-456" }, "Order": { "Id": "321-124", "Date": "10.01.2021", "Status": "open" } }'''.getBytes("UTF-8")

Do not forget to include the parameters created from the JasperReports Activity as output in the step Init.
In our example, the parameters LogoImage and FileUDt are locally saved image or text files that are converted to FileUDT (a userdefined Data type in Aristaflow processes) and displayed in the report. In the case of the image, it is sufficient if you assign the parameter $P{LogoImage} directly to the picture element. At text files you have to get the data from the file with the method getData(). The total expression is then new String($P{FildeUDT}.getData(), "utf-8"). Additionally you can read the appropriate expressions for these element fields in the report from the next picture.

In the lower half of the report we present data about the customer and their order. To do this, we get the data from a Json object Json by accessing the fields for example with this expression $P{Json}.getJSONObject("Customer").getString("Adress"). You can see a possible assignment for the Json object above in the Scripting Activity. We can set up our Json-Object in the report as follows.

Afterwards the rendered PDF looks like this:

Example: Groovy as language

The default language in Jaspersoft Studio is Java, but Groovy is also supported. To be able to use Groovy expressions you have to select Groovy as language in the properties of the report.

The JasperReports Activity renders also PDF of the reports with Groovy as language. But for this you need libraries that you have to integrate in your report. There are two jar files that you have to add to the build path: groovy-json-3.0.2-indy.jar and aristaflow-bpm-platfom.jar. Put these jar files into the Jasper project, right click on them: -> Build Path -> Add to Build Path. These are then listed under the Referenced Libraries.

In this example you can see how easy it is to navigate nested Json files with Groovy expressions. We take the report from the previous example again, but replace the Json object with a Json file of the type de.aristaflow.adept2.model.datamanagement.UDTValue. The Json file will later be transferred as a parameter from the BPM-process.

Now we can access this parameter via Groovy expressions. We use Json slurper to parse the content of the json file into a data structure of lists and we put the expression new groovy.json.JsonSlurper().parse($P{Json}.getValueAsArray(), "utf-8") in a variable for clarity. In our example we create a variable Customer of the type java.lang.Object as follows.

Now you can use the dot notation to navigate to the desired node in the Json file like $V{Customer}.Customer.Name.

Example: Create table with Json-File from process

In this example we pass a Json-File as parameter from BPM-process to the report and display the content of the file in a table. The Json-File contents data about Customer and their orders. Due to the list-like structure of the order data, we can only display them in a table.

Firstly, we create a parameter for example CustomerOrder in the report for the Jsonfile with the Value Class

For the table we need a dataset in JasperReports. Since the data is passed from the process, we create an empty Json-Dataset.
At query dialog of the dataset we don't take any Data Adapter, choose JSON as language and add manually the appropriate fields Id, Date, Status, Item to the dataset. Don't forget to set the node Order from which the data should be extracted.

For the display in the report, we need a table that uses the dataset that has just been created as a data source.

Use the JRDatasource expression $P{CustomerOrder}.subDataSource("Order") to access the fields from the Json-File.

Select all datafields to display in the table.

The JsonFile you can define in Scripting Activity as follows.

$CustomerOrder = '''
 "CustomerId": "012-3456",
 "Name": "John Smith",
 "Adress": "30 Living Street, London",
 "Phone": "800-123-456",
     "Id" : "0987-654",
     "Date" : "10.01.2021",
     "Status" : "open",
     "Item" : "Smartphone"},  
{ "Id" : "654-123", "Date" : "08.09.2020", "Status" : "closed", "Item" : "TV"} ]

Finally the table in rendered PDF looks like this:

Example: JsonFile as Datasource

In this example we take the Json-File from previous example as Data Adapter in the report. To do this, we create a new Data Adapter Json Data Adapter and add the JsonFile add as Data source. Select json as language and enter "." as expression shown in the next image.

At the query dialog of the report we select the Data Adapter we just created and click on Read Fields.

The fields CustomerId, Name, Adress and Phone we can display in a text field. But for the Order we have to take a table.
Now we create a new dataset for the table from Data Source.

Select the Data Adapter Json Data Adapter and enter the node Order for the data read from.
Finally include all fields to the dataset.

Then we create a table using the dataset we just created.

For the connection enter the expression (($P{REPORT_DATA_SOURCE}).subDataSource("Order") in the text box and then select all fields to display the table columns.

Finally our modeled report template looks like this:

When this report is integrated into the JasperReports Activity, an appropriate input parameter is automatically created. This input parameter will be created, if the main data source is JSON and JSON is used as the language (not jsonql). REPORT_DATA_SOURCE is the autogenerated parameter of the type application/json in the next image.

The data of the Json-File can be assigned to this parameter in the Sripting Activity.
The rendered PDF looks like this: