0% found this document useful (0 votes)
220 views33 pages

Jaspersoft Studio - Getting Started, Best Practices, Troubleshooting

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
220 views33 pages

Jaspersoft Studio - Getting Started, Best Practices, Troubleshooting

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Reporting & Analytics

1
Legal Notice
Software Copyright © 2004-2021 SumTotal Systems, LLC. All rights reserved.

Documentation Copyright © 2004-2021 SumTotal Systems, LLC. All rights reserved.

Possession, use, or copying of the software described in this publication is authorized only pursuant to a valid written
license from SumTotal Systems, LLC, ("SumTotal"). Use, duplication, or disclosure by the Government is subject to
restrictions as set forth in subparagraphs (.c) (1) (ii) of the Rights in Technical Data and Computer Software clause at
DFARS 252.227-7013. Under Copyright Law, neither the documentation nor the software can be copied, photocopied,
reproduced, translated, or reduced to any electronic medium or machine-readable form, in whole or in part, without
prior written consent of SumTotal.

Information in this document is subject to change without notice. Companies, names, and data used in examples herein
are fictitious unless otherwise noted.

SumTotal makes no representations that the use of its products in the manner described in this publication will not
infringe on existing or future patent rights, nor do the descriptions contained in this publication imply the granting of
licenses to make, use, or sell software in accordance with the description.

SumTotal Systems, the SumTotal Systems logo, elixHR® Platform, Talent Expansion Suite™, SumTotal Talent, SumTotal
Learn, SumTotal Work, ToolBook, the ToolBook logo, Aspen, the Aspen logo, Learn, TotalLCMS, TotalVCS,
TotalInformation, TotalCollaboration, TotalAccess, TotalVersioning, TotalPerformance, SumTotal Apex Le arning™,
SumTotal Apex™, SumTotal CMX™, SumTotal PeopleOS™, SumTotal CaseOne™, SumTotal Lightyear™, My Softscape™,
SumTotal Payroll, Accero, Cyborg Systems, eCyborg, Accero Cyborg, Fast Forward, Accero Self Service, Payroll Portal,
Workforce Intelligence, SumTotal Workforce Management, and SumTotal Expense Management are either trademarks
or registered trademarks of SumTotal. Specifications and other details listed are accurate as of printing, and may change
without notice.

The following are third-party trademarks:


Windows 95, Windows NT, Windows 2000, Windows XP, Windows 7, Windows 8, Windows 8.1, Windows 10, Windows
Mobile, Word, Excel, Internet Explorer, and Edge are trademarks of Microsoft Corporation. Microsoft is a registered
trademark of Microsoft Corporation. BlackBerry and PlayBook are trademarks owned by Research In Motion Limited.
Chrome and Android are trademarks of Google Inc. Safari and iPad are trademarks of Apple Inc. IBM and Cognos are
trademarks of International Business Machines Corporation.

All other trademarks and registered trademarks are the property of their respective holders.

Publication Date: February 2021

Printed and reproduced in the United States of America


SumTotal Systems, LLC
107 Northeastern Blvd., Nashua, NH 03062 USA

2
Contents
Legal Notice ......................................................................................................................................................................................2

Contents.............................................................................................................................................................................................3
Author’s Note ...................................................................................................................................................................................5

JRXML Files on Connect ................................................................................................................................................................5


Queries – A Billable Engagement .............................................................................................................................................5
Installing Jaspersoft Studio .........................................................................................................................................................6
Introduction to Jaspersoft Studio .............................................................................................................................................7

JasperReports Server ................................................................................................................................................................7


Report Life Cycle.........................................................................................................................................................................8

User Interface ..................................................................................................................................................................................9

Multi-tab Editor ...........................................................................................................................................................................9


Views ............................................................................................................................................................................................ 10

Designing a Report ..................................................................................................................................................................... 12


Create a Report ........................................................................................................................................................................ 12

Add More Fields to the Report ........................................................................................................................................... 15


Preview Tab ............................................................................................................................................................................... 17

Create a Project Folder ......................................................................................................................................................... 18


Report Structure .......................................................................................................................................................................... 19

Design Tab ................................................................................................................................................................................. 19


Bands ........................................................................................................................................................................................... 19

Band Types............................................................................................................................................................................ 21
Specifying Report Properties.............................................................................................................................................. 21

Columns...................................................................................................................................................................................... 23

Exporting Reports with Jaspersoft Studio .......................................................................................................................... 24


Compiling the Report ............................................................................................................................................................ 24

Preview & Exporting............................................................................................................................................................... 25


Best Practices................................................................................................................................................................................ 27

Joins .............................................................................................................................................................................................. 27
Image Files ................................................................................................................................................................................. 27

RM Queries ................................................................................................................................................................................ 27
Common Errors ....................................................................................................................................................................... 28

3
Additional Resources ................................................................................................................................................................. 29

Jaspersoft Community .......................................................................................................................................................... 29


SumTotal Connect .................................................................................................................................................................. 29

Ask the Experts .................................................................................................................................................................... 29


Appendix A: Best Practices to Create a JRXML Report Query .................................................................................... 30

Reported Issue ......................................................................................................................................................................... 30


Analysis ....................................................................................................................................................................................... 30
Best Practice: Create a Custom Report in SQL 2014 ................................................................................................. 30

4
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Author’s Note
Much of the information provided in this reference guide is taken directly from the Jaspersoft
Community. The scope of this document is limited to topics included in the Getting Started portion of
the Jaspersoft Studio Tutorials Archive.

Additional information was provided by SumTotal Customer Support, including Best Practices and Best
Practices to Create a JRXML Report Query.

JRXML Files on Connect


The JRXML source files for all Delivered Reports are available for download on SumTotal Connect 1. Visit
the Reporting documentation page on Connect, click on your respective release, and download the
files today!

You can download the JRXMLs from the community site for OOB reports for every release.

Queries – A Billable Engagement


SumTotal’s Customer Support team cannot extend its support in writing queries from scratch as it is a
billable engagement from the PSE team. To schedule an engagement, contact your Account manager.

1
For the 18.1 release and onward.
5
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Installing Jaspersoft Studio


To learn more about installing Jaspersoft Studio, including requirements, available packages, and more,
please review the Installing Jaspersoft Studio section of the TIBCO Jaspersoft Studio User Guide.

Download location: http://community.jaspersoft.com/project/jaspersoft-studio

Note: There are two versions available, Community Edition and Commercial Edition. We recommen d using
the Commercial Edition.

Note: If you plan on using the .html5 extension in your reports, the Community Edition does not support
them.

6
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Introduction to Jaspersoft Studio

Jaspersoft Studio is a report designer for JasperReports Server. It will help you design and run report
templates; build report queries; write complex expressions; create sophisticated layouts containing
charts, images, subreports, crosstabs; and much more. It integrates TIBCO JasperReports® Server to
create powerful report publishing workflows.

With Jaspersoft Studio you can build documents of any complexity from your data—from print-ready in
PDFs to interactive masterpieces in dynamic HTML, with navigation to interactive components, like
maps and charts that may be inside or outside the report. You can generate high-quality OpenOffice,
PowerPoint, RTF, Word, and spreadsheet documents or you can generate raw CSV, JSON, or XML
documents. It is not difficult to build your own custom exporter to suit any data need.

Using Jaspersoft Studio, you can access your data through a variety of sources including JDBC,
TableModels, JavaBeans, XML, Hibernate, Big Data (such as Hive), CSV, XML/A, as well as cust om
sources, then publish your reports as PDF, RTF, XML, XLS, CSV, HTML, XHTML, text, DOCX, or
OpenOffice.

JasperReports Server
The heart of the TIBCO Jaspersoft® BI Suite is the server, which provides the ability to:
• Easily create new reports based on views designed in an intuitive, web-based, drag and drop Ad
Hoc Editor.
• Efficiently and securely manage many reports.
• Interact with reports, including sorting, changing formatting, entering parameters, and drilling
on data.
• Schedule reports for distribution through email and storage in the repository.

7
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

• Arrange reports and web content to create appealing, data-rich Jaspersoft Dashboards that
quickly convey business trends.

While the Ad Hoc Editor lets users create simple reports, more complex reports can be created outside
of the server. You can either use Jaspersoft® Studio or manually write JRXML code to create a report
that can be run in the server.

Report Life Cycle


When you design a report using Jaspersoft Studio, you are creating a JRXML file, which is an XML
document that contains the definition of the report layout. The layout is completely visual, so you can
ignore the underlying structure of the JRXML file. Before executing a report, the JRXML must be
compiled in a binary object called a Jasper file. Jasper files are what you need in order to run the
reports.

The report execution is performed by passing a Jasper file and a data source to JasperReports.
JasperReports can generate the final document in the format you want.

8
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

User Interface

Multi-tab Editor
Jaspersoft Studio has a multi-tab editor, which includes three tabs that allow you to interact with your
reports in different ways: Design, Source, and Preview:

9
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

• The Design tab is the main one selected when you open a report file and it allows you to
graphically create your report.
• The Source tab contains the JRXML source code for your report.
• The Preview tab lets you run the report preview after having selected a data source and output
format.

Views
You can explore the data using the following views:
• The Repository Explorer View maintains the list of JasperReports Server connections and
available data adapters.
• The Project Explorer View maintains the list of the projects in the current workspace, usually a
Jaspersoft Studio project.
• The Outline View shows the complete structure of the report in a tree. When the Design or
Source tab is active, clicking an element in the Outline view highlights that element in the editor.
The Outline tab is empty when the Preview tab is active.
• The Properties View lets you view and edit the properties of the element that is currently
selected in the report editor or in the Outline view. The properties shown depend on the type of
element. For example, the Properties view for a table shows four tabs: Appearance, Dataset,
Table, and Advanced, while the Properties view for a line shows Appearance, Borders, Line,
Inheritance, and Advanced. Some properties are read-only, but most are editable. When the
root node of a report is selected in Outline view, the Properties view shows the properties for
the report.
o Unlike many other views, you can open multiple instances of the Properties view at one
time and you can pin a selection to a specific Properties view instance. This allows you
to view or edit the properties for a specific element while working with other elements
in your report, or with another report entirely.
• The Problems View shows a list of problems and errors that can, for example, block the correct
compilation of a report.

10
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

• The Report State Summary provides statistics on report compilation/filling/execution. Errors


are shown here as well.

11
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Designing a Report
The report creation process has four main steps:
1. Creating a data source or a database connection is used to fill the report.
2. Designing the report, including the layout of its elements and parameters to represent the data.
3. Running the report, which includes compiling the JRXML source file in a Jasper file and filling in
the data for export or onscreen display.

Create a Report
To create a new report:
1. Select File > New > Jasper Report.
2. The New Report Wizard opens. Select a report from a template2. Click Next.

3. The Report File page opens in the wizard. Navigate to the folder you want the report in and
name the report. Click Next.
4. The Data Source page opens in the wizard. The data source is the location from which the data
is taken to fill the report. In this step, you must select a data adapter, which is essentially a
connection to a data source. Select the data source on the left and enter the appropriate query
on the right. Click Next.

2
A template defines the initial graphical layout of a report.
12
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

a. Selecting the data adapter "One Empty Record - Empty rows": This is the default data
adapter used to create a report without any data. It can be used to define the layout of
the report before connecting it to a data source. In fact, a data source can be provided
at a later time, after the creation of the report.
b. Creating a new data adapter with the "New" button: Jaspersoft Studio supports a wide
variety of data sources. Using the "New" button allows you to browse and connect to an
existing data source.
Note: A SQL database can contain many tables, with many fields, so we must specify which of
these fields we will use in the report. To do this we must provide an SQL query that selects all
the fields we want to include in the report. Using this query ensures the database will be
explored and all the fields found can be added to the report.
5. The Fields page opens in the wizard. Select the desired dataset fields and add them to your
report. Click Next.

13
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

a. On the left, there are all the discovered fields, and on the right the ones that will be
added to the report. Move one or more elements from the left list to the right one using
the buttons between the two lists or by double-clicking on the field.
6. The Grouping page opens in the wizard. Click Next to finish.
7. Jaspersoft Studio builds the report layout with the selected fields included.

14
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Add More Fields to the Report


You may discover that you need to add more fields from the data source after the report was created.
You can add fields to an existing report without creating an entirely new report.

To add fields to an already created report, select the main node of the report from the outline view (in
this example is named "coffee"). From the properties tab press the button Edit query, filter and sort
option, as shown in the following figure:

15
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

In the dialog that appears, you can specify a new query and by clicking the button Read Fields and then
"OK". All the fields discovered are added as new fields in the report. Note that if the new query
discovers fewer fields than the ones used in the existing report, the fields that are not included in the
new query will be removed from the report. An example can be seen in the following figure:

16
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

As you can see, we selected only the fields ORDERID and CUSTOMERID, so any field previously added
to the report that is not included in these two will be removed. This dialog is very powerful - from here,
you can change the data source, add, remove and reorder the fields discovered by the new query.

Preview Tab
The Preview tab lets you preview the report inside Jaspersoft Studio. Click the Preview tab at the
bottom of the report. The preview compiles the report in the background with data retrieved by the
query through your JDBC connection. The Detail band repeats for every row in the query results,
creating a simple table report.

17
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

The Preview tab has the following three areas:


1. Main menu: Displays options for viewing, exporting, and creating data snapshots.
2. Parameters panel: Automatically displayed for a report that has parameters that have been
specified for prompting; otherwise it is hidden.
3. Report preview.

Create a Project Folder


Project folders help you organize your reports. For more information on project folders, please refer to
the Designing a Report with Jaspersoft Studio, available on the Jaspersoft Community.

18
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Report Structure
Design Tab
You design a report using the Design tab, which is divided into different horizontal portions, named
bands, where you can place report elements. When the report design is combined with the data to
generate the print, each band is printed multiple times based on its function (and according to the
rules that the report designer has set). For instance, the page header is repeated at the beginning of
every page, while the detail band is repeated for each record.

Jaspersoft Studio provides a graphical interface for creating JRXML files. The layout is visual, so you can
ignore the underlying structure of the JRXML. You can specify the precise page locations of different
types of text and data, such as title, footers, detailed records, groups, and summary information. Some
portions of a page defined in this way are reused, others stretch to fit the content, and so on.
Additional tools let you add charts and subreports, set up an optional query retrieve data out of a data
source, and more.

Bands
The type page is divided into nine predefined bands to which new groups are added. In addition,
Jaspersoft Studio manages a heading band (group header) and a recapitulation band (group footer) for
every group.

19
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

A band is always wide as the page width (right and left margins excluded). However, its height, even if it
is established during the design phase, can vary during the print creation according to the contained
elements; it can "lengthen" toward the bottom of a page in an arbitrary way. This typically occurs when
bands contain subreports or text fields that have to adapt to the content vertically. Generally, the
height specified by the user should be considered "the minimal height" of the band. Not all bands can
be stretched dynamically according to the content, in particular the column footer, page footer and last
page footer bands.

The sum of all band heights (except for the background) has to always be less than or equal to the
page height minus the top and bottom margins.

20
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Band Types
Band Name Description
Title The title band is the first visible band. It is created only once and can be printed on a
separate page. It is not possible during design to exceed the report page height (top
and bottom margins are included). If the title is printed on a separate page, this
band height is not included in the calculation of the total sum of all band heights.
Page Header The page header band allows you to define a page header. The height specified
during the design phase usually does not change during the creation process,
except for the insertion of vertically resizable components such as text fields. The
page header appears on all printed pages in the position defined during the design
phase. Title and summary bands do not include the page header when printed on a
separate page.
Column Header The column header band is printed at the beginning of each detail column. Usually,
labels containing the column names of a tabular report are inserted in this band.
Group Header A report can contain zero or more group bands which permit the collection of
detailed records in real groups. A group header is always accompanied by a group
footer (both can be independently visible or not). Different properties are associated
with a group. They determine its behavior from the graphic point of view. It is
possible to always force a group header on a new page or in a new column and to
print this band on all pages if the bands below it overflow the single page (as a page
header, but at group level). It is possible to fix a minimum height required to print a
group header: if it exceeds this height, the group header band is printed on a new
page (please note that a value too large for this property can create an infinite loop
during printing).
Group Footer The group footer band completes a group. Usually, it contains fields to view
subtotals or separation graphic elements, such as lines.
Column Footer The column footer band appears at the end of every column. Its dimension is not
resizable at run time (not even if it contains resizable elements such as subreports
or text fields with a variable number of text lines).
Page Footer The column footer band appears at the end of every column. Its dimension is not
resizable at run time (not even if it contains resizable elements such as subreports
or text fields with a variable number of text lines).
Last Page Footer If you want to make the last page footer different from the other footers, it is
possible to use the special last page footer band. If the band height is 0, it is
completely ignored, and the layout established for the common page is used for the
last page.
Summary The summary band allows you to insert fields containing total calculations, means,
or any other information you want to include at the end of the report.
Background The background enables you to create watermarks and similar effects, such as a
frame around the whole page. It can have a maximum height equal to the page
height.

Specifying Report Properties


To view or edit report properties, select the report root node in the Outline view. The report properties
are shown in the Properties view.

21
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

To change the page dimensions of a report, click the Report tab in the Properties view for the report,
then click Edit Page Format to open the Page Format dialog. Here you can edit the width, height, units,
orientation and margins of the report.

In the dialog that will appear you can change the page dimensions.

22
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Note: The page orientation options, Landscape or Portrait, in reality, are not meaningful, because the page
dimensions are characterized by width and height independent of the sheet orientation. However, this
property can be used by certain report exporters.

Columns
As you have seen, a report is divided into horizontal sections: bands. The page, one or more of which
make up a report, presents bands that are independent of the data (such as the title or the page
footers) and other bands that are printed only if there are one or more data records to print (such as
the group headers and the detail band). These last sections can be divided into vertical columns to take
advantage of the available space on the page.

In this context, the concept of a column can be easily confused with that of a field. In fact, a column
does not concern the record fields, but it does concern the detail band. This means that if you have a
record with ten fields and you desire a table view, ten columns are not needed. However, the element
will have to be placed correctly to have a table effect. Ten columns will result when long records lists
(that are horizontally very narrow) are printed.

For more information on Columns, please refer to the Report Structure in Jaspersoft Studio tutorial,
available on the Jaspersoft Community.

23
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Exporting Reports with Jaspersoft


Studio
In addition to generating and viewing reports, Jaspersoft Studio allows you to export reports into many
formats, including PDF, XLS, HTML, and others.

Compiling the Report


When you switch on the Preview tab in the designer bottom bar, Jaspersoft Studio performs a set of
operations to create the final report. The first operation compiles the JRXML source file in a Jasper file.
This first step can fail if the elements are not correctly positioned (for example, if an element is placed
outside of a band), or if an expression in the report has errors and cannot be compiled.

If the compilation runs successfully, the produced Jasper file is loaded and filled using the active
connection or data source. This second operation can also lead to errors. This can happen if the
referenced database is not active, an invalid query has been provided, or a null field produced an error
in an expression during the filling process. If all operations complete without error, the report is
displayed in the integrated viewer. Errors are shown in the Report State window, after clicking the
Errors button, as shown in the following image:

24
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

If errors occur during the compilation, the tab changes from Preview to Design.

Preview & Exporting


If the compilation completes and there are no errors in the file, the preview is shown. From there you
can browse the generated report and change its visualization, change the data source, or export the
report. Note that after changing the data source the report is recompiled automatically. You can also
change the preview format as well as save the report in different formats.

25
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

In the image above you can see that there is a green Play button. Clicking this button forces the report
to be regenerated; it should be used when a subreport changes, or when you want to execute the
report with different input parameters. When you set a preview format, the report is automatically
regenerated in the chosen format, and the corresponding viewer application is opened - a PDF viewer
or OpenOffice, for example.

26
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Best Practices
Joins
• Do not join real-time tables with ETL-based tables. Real-time tables (replicated tables) are
updated every 5 minutes. ETL tables (dim/fact) are updated every 24 hours. If you join real-time
tables with ETL-based tables, you run the risk of reporting on inaccurate data.
o For example, if you are pulling registration data (real-time) into your report and pulling
completion data (ETL-based) it’s never going to be accurate. People are constantly going
to be registering for and completing training, but the completions aren’t going to show
up in the report because that data hasn’t been captured yet.

Image Files
• Upload images in a common folder in Reporting so that multiple reports can refer to the same
image file.
• When creating reports with images in Jaspersoft Studio, set the On Error Type image property
to Blank. If you do not have Blank selected, the operation that is being sent to the system gets
to the point where it goes to get that image and if we don’t have it set to blank it out under
those circumstances (image not found) it’s not going to know what to do, so it never returns the
report. With Blank set, it ensures the process doesn’t stall and instead goes on to the report
generation phase. “delivers the mail”
• Do not delete or rename an image file (including the file extension) within Jaspersoft Studio to
avoid errors.
o Within Reporting, you can stop sharing this common folder with other users to avoid
issues.

RM Queries
• Use Report Manager Queries (SQL queries used in RDL files – developed in Microsoft BIDS).
Please revise the queries based on the best practices in Appendix A.

27
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Common Errors
Cause Remedy
JDBC Driver Not Configured Confirm the JDBC driver is installed and configured on client and
database servers.
SQL Server is Down Partner with your DBA/ network team and ensure (1) that the
database server is not down and/or (2) that there is network
connectivity.
SQL Server Password Reset Partner with your DBA/ IT team and, if necessary, change or update
the password in database adapters accordingly.
Database Name Changed Partner with your DBA/ IT team if the remote database name is being
changed to a different name.
Database Made Inactive Partner with your DBA/ IT team if the remote database name went to
idle state.
Network Connection Lost to Check to see if the network is down or whether the network to the
Database Server specific database server is down.
Firewall Blocking Partner with your IT team to ensure that Windows firewall/ 3rd party
firewall is not blocking the connection.
SQL Server Port 1433 Partner with your IT team if SQL server port 1433 is blocked at the
Blocked network, firewall. Ask them to allow inbound/outbound traffic to this
port).

28
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Additional Resources
Jaspersoft Community
You can use the following sources of information to learn about JasperReports Server:
• Jaspersoft’s core documentation describes how to install, administer, and Jaspersoft Studio. You
can also access PDF and HTML versions of this guide online from the Documentation section of
the Jaspersoft Community website.
• Jaspersoft’s Ultimate Guides document advanced features and configuration. They also include
best practice recommendations and numerous examples. You can access PDF and HTML
versions of these guides online from the Documentation section of the Jaspersoft Community
website.
• Jaspersoft’s Online Learning Portal lets you learn at your own pace, and covers topics for
developers, system administrators, business users, and data integration users.

SumTotal Connect
Ask the Experts
Click here to access the recording of Advanced Reporting: Best Practices on Report Creation with
Jaspersoft Studio.

29
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

Appendix A: Best Practices to Create


a JRXML Report Query
Reported Issue
Customer reported reports resulted in errors and observed performance issue post migrating to
Winter2016.

Analysis
The upgrade from 2015.1 to W2016 changes the SQL from 2008 to 2014, which is the right thing for a
SaaS vendor.

MS has changed query plan optimizer specially cardinality estimator in 2014 and few queries with
multiple WITHs and CTEs would have bad execution plan and run forever.

Best Practice: Create a Custom Report in SQL


2014
1. Use TEMPORARY (#temp) tables in place of CTEs/WITH clause.
2. Use Star Schema if there is no need of real time data. For example, to populate Manager, Org,
Job hierarchy we can query Analytics.DimEmployee table.
3. In the Input Parameters - for multi select, dropdown use key (pk/fk) value (text) pair and pass
key value to report query to filter the data instead of passing the text to filter the data.
4. Try to avoid ‘NOT IN’, ‘!= / <>’ in the JOIN and WHERE conditions.
5. Use DISTINCT, GROUP BY & ORDER BY conditions only if necessary in the INTERIM tables.
6. Use UNION ALL instead of UNION if we know there won’t be any duplicate output.
7. Use “WITH (NOLOCK)” hints on the StarSchema tables in the report query for the huge tables
like FactAttempt, DimEmployee, etc.
8. Do not use 'table.*' while populating the data, instead only select the columns which are
required for report OR subsequent queries. * will populate all columns into memory, especially
when you are populating data into CTEs OR Temp tables there will be a lot of memory
blocked/used and in turn, the query performance will go down because of resources.

Examples:

Old SQL
;WITH fEmp AS (
SELECT dimUser.*,
Orgs.PosName, Orgs.OpsName, Orgs.FncName, tblEmp.Emp_CompanyCode

30
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

FROM dimUser
LEFT JOIN Orgs ON dimUser.EmpFK=Orgs.EmpFK
LEFT JOIN tblEmp on tblEmp.Emp_PK = dimUser.EmpFK WHERE <<Condition>>
)

New SQL
CREATE TABLE #femp(
[Position] [nvarchar](255) NULL,
[PrimaryJobName] [nvarchar](255) NULL,
[MgrEmpFullName1] [nvarchar](280) NULL,
[EmpNo] [nvarchar](50) NULL,
[EmpLName] [nvarchar](50) NULL,
[EmpFName] [nvarchar](50) NULL,
[OptEmp_Txt1] [nvarchar](255) NULL,
[OptEmp_Txt2] [nvarchar](255) NULL,
[OptEmp_Txt3] [nvarchar](255) NULL,
[OptEmp_Txt4] [nvarchar](255) NULL,
[OptEmp_Dt1] [datetime] NULL,
[EmpCode] [nvarchar](500) NULL,
[EmpStat] [nvarchar](500) NULL,
[PosName] [nvarchar](255) NULL,
[OpsName] [nvarchar](255) NULL,
[FncName] [nvarchar](255) NULL,
[Emp_CompanyCode] [nvarchar](256) NULL,
[ID] [int] NOT NULL,
[OptEmp_Float1] [float] NULL,
[PrimaryOrgName] [nvarchar](255) NULL,
[EmpFK] [int] NULL
);

insert into #fEmp


SELECT dimUser.Position, PrimaryJobName, MgrEmpFullName1, EmpNo, EmpLName,
EmpFName, OptEmp_Txt1, OptEmp_Txt2, OptEmp_Txt3, OptEmp_Txt4, OptEmp_Dt1, EmpCode,
EmpStat, ID, OptEmp_Float1, PrimaryOrgName, dimUser.EmpFK,
Orgs.PosName, Orgs.OpsName, Orgs.FncName, tblEmp.Emp_CompanyCode
FROM dimUser
LEFT JOIN Orgs ON dimUser.EmpFK=Orgs.EmpFK
LEFT JOIN tblEmp on tblEmp.Emp_PK = dimUser.EmpFK
WHERE <<Condition>>

9. Populate only ID/PK/FK columns in the CTEs OR Temporary tables, using ID/PK/FKs populate the
non-ID columns needed by joining the main table in the FINAL SELECT command.

31
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

For example - Only populate EmpFK in CTEs/Temp tables and make a JOIN with DimUser to
populate the other columns like EmpCode, Name, etc. instead of populating the non-Id columns
in the CTEs/Temp tables
Example: Consider the same example which we discussed above.
New SQL: Can be further modified to only fetch the dimUser EmpFk
insert into #fEmp
SELECT dimUser.EmpFK,
Orgs.PosName, Orgs.OpsName, Orgs.FncName, tblEmp.Emp_CompanyCode
FROM dimUser
LEFT JOIN Orgs ON dimUser.EmpFK=Orgs.EmpFK
LEFT JOIN tblEmp on tblEmp.Emp_PK = dimUser.EmpFK
WHERE <<Condition>>

In the FINAL Report SELECT command we can join the ‘dimUser’ with ‘#fEmp’ tables to fetch the
“dimUser.Position, PrimaryJobName, MgrEmpFullName1, EmpNo, EmpLName, EmpFName,
OptEmp_Txt1, OptEmp_Txt2, OptEmp_Txt3, OptEmp_Txt4, OptEmp_Dt1, EmpCode, EmpStat, ID,
OptEmp_Float1, PrimaryOrgName”

10. Add indexes on the WHERE / JOIN ON CONDITION columns on the TEMP tables if the data is
huge.

Example: Consider the same example which we discussed above. If the data is huge in #fEmp,
then create clustered/non-clustered index on the table which will improve the query
performance.

ALTER TABLE #fEmp ADD CONSTRAINT [fe_EmpFK] PRIMARY KEY CLUSTERED


(
[EmpPK] ASC
)

11. When we write a new report query/re-writing existing report query make sure we use CORE
UDM schema instead of depending on the legacy tables (i.e. compatible views).

Example:
a. Use Analytics.Dim*/Fact* in place of factAttempt, factUserRequiredActivity (old RM
StarSchema)
b. Use Person and Person* (UDM) in place of iwc_usr, tblEmp* (legacy compatibility views)

12. In case of recursive CTE, populate the data using CTE and later insert the DATA into TEMP tables
and use the TEMP table in the final SELECT OR next subsequent commands.

;WITH clsHierarch AS (

32
Jaspersoft Studio: Getting Started, Best Practices & Troubleshooting

SELECT fulfilled.ID ffID, fulfilled.Code ffCode, fulfilled.ActivityName ffName, fulfilled.ActivityLabel


ffLabel, fulfilled.ActivityFK ffFK
, fulfilled.ID prevParentID, fulfilled.ActivityFK prevParent
, COALESCE(act.ID,fulfilled.ID) ID, COALESCE(act.Code,fulfilled.Code) Code,
COALESCE(act.ActivityName,fulfilled.ActivityName) ActivityName
, CASE
WHEN fulfilled.ActivityLabel='ILT Course' THEN
COALESCE(act.ActivityLabel,'ILT Class')
ELSE COALESCE(act.ActivityLabel,fulfilled.ActivityLabel)
END ActivityLabel, COALESCE(act.ActivityFK,fulfilled.ActivityFK) ActivityFK,
COALESCE(act.StartDt,NULL) StartDt
, COALESCE(act.EndDt,NULL) EndDt
, 1 AS recurseLvl
, fulfilled.ID intermediateID
FROM (
<<TABLES WITH JOIN CONDITIONS>>
) act ON fulfilled.ActivityFK=act.lnk_LinkedActFK

UNION ALL
--This part of the query links successive 'levels' of fulfilments to the starting query,
repeatedly
SELECT parent.ffID, parent.ffCode, parent.ffName, parent.ffLabel, parent.ffFK, parent.ID,
lnk2.lnk_LinkedActFK, actlower.ID, actlower.Code, actlower.ActivityName, actlower.ActivityLabel,
actlower.ActivityFK, actLower.StartDt, actLower.EndDt, parent.recurseLvl+1, parent.ID
FROM clsHierarch parent
INNER JOIN subscrAct lnk2 ON lnk2.lnk_LinkedActFK=parent.ActivityFK
INNER JOIN dimActivity actLower ON lnk2.lnk_ActivityFK=actLower.ActivityFK
WHERE parent.prevParent<>lnk2.lnk_ActivityFK
-- Make sure the current child is not equal to the previous parent
)

INSERT INTO #clsHierarch select * from clsHierarch;

33

You might also like