You are on page 1of 14

• Implementacion de la Pagina web de la

I.E.
• Implementacion de aulas funcionales.
• Sesiones de Aprendizaje en el Sitio
Oficial de la JEC.
• Implementacion de Plataforma
Educativa Moodle.
• Conexion a otras plataformas
Educativas.
Tips and Tricks – Jaspersoft Development
This document purpose is to give tips and tricks for a jaspersoft developer

Contents
How to Compare jrxmls ................................................................................................................................ 2
How to manually add Fields .......................................................................................................................... 2
Changing the Report Language ..................................................................................................................... 2
Repository Connection Information ............................................................................................................. 3
How to use Markup in a Field ....................................................................................................................... 3
How to Modify an OOTB Report ................................................................................................................... 3
Copy the Report ........................................................................................................................................ 3
Modify the Report..................................................................................................................................... 5
How to modify the colors on a chart ............................................................................................................ 6
How to add a Jaspersoft report into an iFrame ............................................................................................ 7
Increment Date Value ................................................................................................................................... 8
Conditional Styles – Override Issue .............................................................................................................. 8
How to find the number of times a String is in a string ................................................................................ 8
How to set default on a parameters ............................................................................................................. 8
Where is the user id stored in Jaspersoft come from via Clarity .................................................................. 8
Getting the previous value for a variable ..................................................................................................... 9
JasperServer.Api.Metadat.user.domain.User Class ...................................................................................... 9
Adding an Extension Font for PDF Export ................................................................................................... 11
How to set a default date to start of (Year, Month, Day) ........................................................................... 11
How To Set Excel Export To Create New Sheets Per Group ....................................................................... 11
Query Functions with Regex expressions Loading in the DWH .................................................................. 12
Passing Parameters down to sub reports using a HashMap ...................................................................... 12
Scheduled Jobs not Deleted after Report Deleted ................................................................................. 12
LISTAGG Issue Workaround .................................................................................................................... 12
Removing the ability for the user to change graph style ........................................................................ 12

How to Compare jrxmls


1. Download both JRXML’s into a local project.
2. Navigate to the Project Explorer and open the local project.
3. Select both jrxmls to be compared.
4. Right click on one and select “Compare With”.
a. Note: Any changes done during the compare will affect the files. However, if you have
either of them open before the compare, they will show as “not saved” and need to be
closed without saving.

How to manually add Fields


If adding fields to an out of the box report make sure to create the fields manually instead of using
“Read Fields”. You will get errors for all out of the box parameters/resources used. To manually create
fields follow the below steps.

1. Navigate to the outline of the report.


2. Find the section for fields. Click New.
3. Create the field and make sure to give it the same name as the alias is given in the sql query.

Changing the Report Language


Changing the report language can allow the user to use Groovy instead of Java methods in expressions.
This can also lead to troubleshooting issues. If you see the below images please check your report
language.
Repository Connection Information
On all environments you can find the connection information under Admin -> System Options (section
Advanced Reporting)

How to use Markup in a Field


Markup is a style choice that allows you to apply style inside the expression.

Ex: http://community.jaspersoft.com/questions/534014/use-style-text-expression

To do this follow the steps.

1. Navigate to the properties of the textfield


2. Make sure to select the markup language to use.

a.
3. Once this is applied you can apply the selected markup in your textfield expression.
a. Example: I want my field “name” to be bold. I am using the markup “Styled”.
"<style isBold='true'>" + $F{NAME} + "</style>" + " - " +
($F{SR_UPDATE} != null ? $F{SR_UPDATE} : "No Update")

How to Modify an OOTB Report


Copy the Report
1. Navigate to the Clarity environment for development.
2. Navigate to the Advanced Reporting link.
3. In the advanced reporting home page, click on the repository link on the top right menu under
the View column.
4. Filter for the report you want to modify.
5. Right Click on the report and select the option “Copy”

6. Navigate to the folder to keep the new report.


7. When in the folder click the button “Paste”.

8. This will copy the entire Report Unit into this folder. This will allow us to edit the report via
Studio without modifying the original report.
Modify the Report
1. Open Jaspersoft Studio.
2. Open the local workspace and create a Jaspersoft project to store the jrxml that will be updated.
3. Navigate to the Repository in which the new copied report is stored.
4. Find the JRXML report file to be edited. Open the properties for this file by right clicking on the
file and selecting properties

5. Once in the properties of the jrxml, download the file to the workspace created in step 2.

6. Modify the jrxml to your specifications.


a. Note: Anytime you want to test a change, follow the steps below to publish and test.
Changes to OOTB reports cannot be viewed locally without removing tags referencing
the templates and stored repository resources.
7. Save your changes to the jrxml in your local workspace.
8. Navigate back to the properties menu of the jrxml on the repository.
9. Select the “Upload from Workspace” to upload the modified jrxml file.

10. Now the report has been edited and can be ran on the environment without issue.
How to modify the colors on a chart
Edit Chart Properties -> Chart Data tab -> Configuration tab -> Click on Category Level -> Click Modify
button -> Go to Bucket Properties tab. Click Add. Name the property color and give it an expression to
define the color of the slice. Here’s an example:

$F{PRIORITY_NUM} == 3 ? "#CC0022" : $F{PRIORITY_NUM} == 2 ? "#FFBB44" : $F{PRIORITY_NUM} == 1 ?


"#559911" : "#E8EBF2"

Now go to Advanced Properties on the Configuration tab. Click Add.

Here’s what the property should look like:


How to add a Jaspersoft report into an iFrame
First, extracting the link parameter (This all goes in an HTML portlet). This method only pulls one
parameter, if you need multiple, it would be an easy change:

<script>

var str = window.location.href;

var key = "";

vars = str.split("&");

for (var i=0;i<vars.length;i++) {

var pair = vars[i].split("=");

if (pair[0] == "id") {

key = pair[1];

</script>

Second, we can now add the following line inside the “script” tags, after the above code, to update
the iFrame source location. In this example, we’re linking to a quick project list report, passing the
parameter projectKey_1 and updating the iFrame with id “projectList”:

document.getElementById('projectList').src = 'https://cppm1080-
dev.ondemand.ca.com/reportservice/flow.html?_flowId=viewReportFlow&standAlone=true&decorate=
no&ParentFolderUri=/users/regoconsulting/reports&reportUnit=/users/regoconsulting/reports/Project
List&projectKey_1=' + key;

Lastly, the iFrame line for the HTML Portlet:

<iframe id="projectList" width="1024" height="400" src=""></iframe>

Note: Not hard coding the iframe size results in poor sizing for the report
Increment Date Value
The function EDate lets you add and subtract months. You would need to figure out how to subtract
days by a %. Example below.
EDATE(NOW(),6)

Conditional Styles – Override Issue


When working with Conditional Styles, by default, they will not override the element property, if
set. For example, if you have a TextField, which you have set to be red forecolor and a grey backcolor,
and then apply a Style which changes the back and fore color, the element property will take precedent,
and you won’t see the style changes applied.

You can remove the styles from the GUI but an easier route is removing from the source. Example
below.

<reportElement mode="Opaque" style=“TestStyle" x="674" y="20" width="110" height="20"


forecolor="#000000" backcolor="#77BCD4”/>

Removing the “attributes” of the report element will allow the style to work.

<reportElement mode="Opaque" style=“TestStyle" x="674" y="20" width="110" height="20”/>

How to find the number of times a String is in a string


Using the split and length function you can determine the amount of times a certain character set
appears in a string.
$F{CURRENT_STATUS_COMMENTS}.split("[\\r\\n]+").length

How to set default on a parameters


This will demonstrate how to set defaults on parameters for single value and multi value parameters.

In the default value expression on a parameter set the value that would be passed via the input control.

Boolean: TRUE

Collection: new ArrayList(Arrays.asList(5006063))

Integer: 5006063

Where is the user id stored in Jaspersoft come from via Clarity


Cmn_sec_users table has a new field called user_uid. That is the one which is in jasperserver.
Getting the previous value for a variable
<variable name="INITIAL" class="java.math.BigDecimal">
<variableExpression><![CDATA[$V{x}]]></variableExpression>
</variable>

JasperServer.Api.Metadat.user.domain.User Class
public interface com.jaspersoft.jasperserver.api.metadata.user.domain.User extends
com.jaspersoft.jasperserver.api.common.domain.AttributedObject,com.jaspersoft.jasperserver.api.met
adata.user.domain.TenantQualified {

public static final java.lang.String URI_PROTOCOL;

public abstract java.lang.String getUsername();

public abstract void setUsername(java.lang.String);

public abstract java.lang.String getFullName();

public abstract void setFullName(java.lang.String);

public abstract java.lang.String getPassword();

public abstract void setPassword(java.lang.String);

public abstract java.lang.String getEmailAddress();

public abstract void setEmailAddress(java.lang.String);

public abstract boolean isExternallyDefined();

public abstract void setExternallyDefined(boolean);

public abstract boolean isEnabled();

public abstract void setEnabled(boolean);

public abstract java.util.Set getRoles();

public abstract void setRoles(java.util.Set);

public abstract void addRole(com.jaspersoft.jasperserver.api.metadata.user.domain.Role);

public abstract void removeRole(com.jaspersoft.jasperserver.api.metadata.user.domain.Role);

public abstract java.util.Date getPreviousPasswordChangeTime();

public abstract void setPreviousPasswordChangeTime(java.util.Date);

public abstract java.util.List getAttributes();


public abstract void setAttributes(java.util.List);

}
Adding an Extension Font for PDF Export
Adding a PDF Font Style to be exported can help when a font is not available out of the box in the PDF
Exporter. The following steps show how to add one.

1. Download the TTF for the font that you need to use. Make sure to get both the BD (Bold),
regular, and italicized versions available. Note: Some fonts do not have italics, research will be
needed.
2. Add the TTFs to the jaspersoft server.
a. Create custom font folder
b. Right Click on folder and click add File -> Font
c. Add the TTF and click submit
d. Navigate to the properties and copy the path.
3. Once the path has been copied, embed it in the following syntax pdfFontName=“path”
a. Ex: pdfFontName="repo:/Custom_Reports/Custom_Fonts/tahomabd.ttf"
4. Navigate to jaspersoft studio and in the style or on the text field directly add the tag you saved
in step 3.
Ex. <style name="Section_Header" mode="Opaque"
backcolor="rgba(228, 126, 2, 0.2509804)" fontName="Tahoma"
fontSize="12" isBold="true"
pdfFontName="repo:/Custom_Reports/Custom_Fonts/tahomabd.ttf"/>

How to set a default date to start of (Year, Month, Day)


The following expression can be modified to get the first of any month.
Synatx: new Date(YEAR,MONTH(0-11),DAY(1-31))

Get last day of current year example: new Date(new Date().getYear(),11,31)

Get last day of current year example: new Date(new Date().getYear(),0,1)

Note: If you need the end month dates to be relative, make sure to do a
DAYSINMONTH expression.

How To Set Excel Export To Create New Sheets Per Group


Add the parameters for Break.Before.Row in the group footer. See example below for syntax.

Also add the xls.sheet.name and use an expression to name it based on the group.
<reportElement style="Section_Header" x="0" y="0" width="2100" height="30"
uuid="1805e2ec-3348-48bb-ba88-758166a1c8bb">
<property
name="net.sf.jasperreports.export.xls.break.before.row" value="true"/>
<propertyExpression
name="net.sf.jasperreports.export.xls.sheet.name"><![CDATA[$F{FUNCTIONAL_LEAD
_GROUP}!= null ? $F{FUNCTIONAL_LEAD_GROUP} : "No Functional
Lead"]]></propertyExpression>
</reportElement>
Query Functions with Regex expressions Loading in the DWH
With the Query lookups, if you have REGEXP functions, it may give a DWH Load error. You will need to
replace that with older style functions.

Also if you have SUBSTR, you may get an error on the DWH load. If you do, then change it to
@SUBSTR@.

Similarly with NVL, if you have it in lookup where clause change it to @NVL@.

Passing Parameters down to sub reports using a HashMap


<parametersMapExpression><![CDATA[new
java.util.HashMap($P{REPORT_PARAMETERS_MAP})]]></parametersMapExpression>

Way easier than writing each one out, especially when your creating a report book that can have 5+
parts

Scheduled Jobs not Deleted after Report Deleted


When you delete a report that has scheduled jobs assigned to it, the jobs do not get deleted. However,
they are removed from the interface. To change this on premise see the link below.

http://community.jaspersoft.com/documentation/tibco-jasperreports-server-administrator-
guide/v60/scheduler-running-deleted-jobs

LISTAGG Issue Workaround


When using the function LISTAGG to concatenate an MVL In oracle I used the “,” to separate. Jaspersoft
server has some security around SQL injection, so the report worked on my machine but it failed on the
server, I thought we should put this in the document as well. I ended up replacing the ‘;’ by ‘ – ‘ and
everything worked.

Removing the ability for the user to change graph style


Adding the property on the chart will allow this functionality to be removed.

com.jaspersoft.jasperreports.highcharts.interactive = “false”
How to Hyperlink from your report
To hyperlink to your report you need to define a textfield or object to put the hyperlink on. This can be
an image, text field, etc.

1. Go into Jaspersoft Studio and find your resource on the report you want the user to select to
link to another report or website.
2. Navigate to the properties of the resource

3. Expand the Hyperlink section


4.
5. If linking to an external URL like a website, use the Link Target as Blank. Link Type Reference,
and pass in your link via a string. A good example of this type of URL Link is on the Project Status
Details, the section More Issues and More Risks, links showcase this well.

6.
7. If linking to an external URL, like another report, use the Link Target as Self. Link Type ahs
ReportExecution.

8.
9. In the parameters, make sure to define the parameter _report and the URI the report is located
in the repository. Ex: "/Custom_Reports/Top_20_Dashboard"
a. Note: You can also add additional parameters to pass to the report such as INVKEY, just
like you would a sub report.
b. Note: We have seen bugs with collection parameters, so test thoroughly.

You might also like