Changes

Jump to: navigation, search

Create iReport Templates with Subreports

485 bytes added, 17:47, 24 August 2015
m
{{TOC right}}
==Creating Subreports==__NOEDITSECTION__
A Subreport subreport is a report within a report; thus, providing a way to generate a report that includes data on the target IMSMA Item item as well as data on other IMSMA Items items that are associated to the target IMSMA Itemitem. Generally a subreport is used in a situation where you have one or more sets of data relating to a single IMSMA item. A common use case would be a Location report with multiple details bands of different IMSMA items (Land, Activity, Accident, Victim, Education, and QM).
Regardless of what IMSMA data you’re including in your report and sub-reportssubreports, there are 5 basic steps to create a report with subreports::Step 1 – Create the Main main report:Step 2 – Add Sub-report a subreport to the Main main report:Step 3 – Add Parameter a parameter to the Subreportsubreport:Step 4 – Define Report Query the report query for the Subreportsubreport:Step 5 – Add Subreport Parameter subreport parameter to the Main main report
====Step 1 – Create the Main Report====__NOEDITSECTION__
Before creating the main report, you will need to determine what data to should be included on in your report. For example, if you are creating a report about Land with all the Progress Report data, then the target IMSMA item for your main report should be Land and the target data for your sub-report subreport should be Activity assuming that Progress Reports are entered into the system as Activity. Below is a list of questions and things to be considered when designing a report.
*What are all the data to be included on the report?
*What is the target IMSMA Item item for the Main main report? This is the primary data of your report.*What is the target IMSMA Item item for the sub-reportssubreports? This is the secondary data of your report.
*Determine the relationship between the primary data and the secondary data. How did they get reconciled to one another? How are they linked?
The Main main report should be created with the IMSMA item determined to be the primary data of your report. The Main main report is just a basic report and can be created using the steps provided in the [[Create a Basic i-Report iReport Template]] section.
====Step 2 – Add Subreport to the Main report====__NOEDITSECTION__
#:[[Image:IReportSubReportPalette.png|center|300px|''Subreport Palette'']]<div align="center">''Subreport Palette''</div>
# Release the button and the window below displays.
#:[[Image:IReportSubReport1.png|center|500px|''Add Sub-report Subreport to the Main report'']]# Click '''Next''' to define a new sub-report subreport unless you have an existing report that you would like to use for sub-reportsubreport.
# Select the desired iReport Template to apply (Blank is recommended).
#:[[Image:IReportSubReport2.png|center|500px|''Select the desired iReport Template'']]
# Select from the '''Connection/Data Source''' list. This should be the IMSMA item determined as the secondary data of your report. For example, if you are creating a report about Land with Progress Reports, then “Hazard Reduction” should be the data source for the sub-reportsubreport. Click Next.
#:[[Image:IReportSubReport3.png|center|500px|''Select the desired datasource'']]
# Select the attributes to be included in your sub-reportsubreport. Click '''Next'''.
#:[[Image:IReportSubReport4.png|center|500px|''Select the desired fields for the subreport'']]
# Select the fields to group by. This step is not required. Click '''Next'''.
#:[[Image:Subreport_Group_by.png|center|500px|''Select the fields to group by'']]
# Enter a name for the sub-report subreport or use the default. Choose '''Next'''.
#:[[Image:IReportSubReport5.png|center|500px|''Enter a name for the subreport'']]
# Select '''Use the same connection used to fill master report'''. Click Finish.
#:[[Image:IReportSubReport6.png|center|500px|''Use same connection'']]
# The sub-report subreport displays.
====Step 3 – Add Parameter to Subreport====__NOEDITSECTION__
To connect a subreport to the Main main report, we next need to create a parameter for passing the identification (guid) of the primary IMSMA Item item between the subreport and the main report. In the '''Report Inspector''' on the subreport, [[Modify an iReport Template#Adding a Parameter to an iReport Template|add a Parameter]] to hold the guid of the IMSMA Item item on the main report. It is recommended to add a fairly generic parameter name such as ''ItemGUID'' so that the subreport can be more easily re-used.
# From the Report Inspector, '''right click''' on the '''Parameter''' tree and choose '''Add Parameter'''.
#: [[Image:IReport AddParameter1.png|center|250px|''Add Parameter'']]
# In the '''Properties''' pane, enter a parameter name (e.g. ItemGUID} and edit any other properties. Normally it is not required to edit anything other than the name, you might however want to deselect the '''Use as a prompt''' option.
#: [[Image:IReport AddParameter2.png|center|250px|''Add Parameter'']]
# Once the parameter is added it will be available in the '''Report Inspector''' and can be referenced as ''$P{parametername}''. For example:
====Step 4 – Define Report Query for Subreport====__NOEDITSECTION__
The next step is to create a report query for the subreport you just created in Step 3 2 to define how the IMSMA item on the Main main report is related to the IMSMA item on the subreport. Typically the subreport Report Query report query will receive the guid from the main report via the parameter created in Step 4 3 and then use it to limit items in the subreport to those linked to the main report. Below is the instructions on how to define the Report Queryreport query:
# Open the [[Modify an iReport Template#Using Report Query filters|Report Query report query window]].# From the Report report query window, select '''ImsmaQuery''' from the Query query language list.# Enter a Report Query report query filter using the parameter defined above to limit the objects according to the main report object. The most common Report Query report query filter would be to filter to only linked objects. For example '''''links.toGuid="$P{ItemGUID}"'''''. In this step, the Report Query tells the subreport to return only rows that are linked to the guid of the the item in the main report via the link table. Other combinations of Report Query report query filters can be used on subreports beyond the link table. These are documented in the [[#Example Subreport Relationships|Possible Subreport Relationships]] section below.# Click '''OK'''. The Report report query window closes.
# Save the subreport.
====Step 5 – Add Link the Subreport Parameter to the Main Report====__NOEDITSECTION__We created a parameter on Now that both the sub-report to connect to main and the Main report in Step 3subreport are ready, now we need the only thing that remains to create a parameter on be done is linking the Main report as welltwo together. Below is are the instructions to create link the parameter you need for the Main reporttwo reports:# Make sure you are at the Main main report by selecting the name of the Main main report from the tabs at the top of the iReport Designer canvas pane.# Select the subreport box within the Main main report.
#: [[Image:IReportSubReportSelection.png|center|500px|''Select the Subreport on the main report'']]<div align="center">''Select the Subreport on the main report''</div>
# On the '''Properties''' pane for the Subreport, select the '''Parameter''' selector.
#: [[Image:IReport_SubReportProperties.png|center|200px|''Subreport properties'']]<div align="center">''Subreport properties''</div>
# '''Add''' a parameter and give it a type '''exactly the name of the subreport parameter created in step 3''' (e.g. ''ItemGUID'')
#: [[Image:IReport_SubReportParameter.png|center|200px|''Add a parameter'']]<div align="center">''Add a parameter''</div>
# For the '''value expression''', select the appropriate field to include in the parameter. '''Normally this is ''$F{guid}''''' but other choices are available.
#: [[Image:IReport_SubReportParameter2.png|center|200px|''Select the appropriate field'']]<div align="center">''Select the field to include in the parameter''</div>
# Click '''OK''' and close Subreport Parameters window.
 
You are now ready to run your main report. Running (i.e. previewing) the main report will automatically run the subreport(s) as well, and the data from the main as well as from the subreport(s) will be included in the output.
==Kinds of Subreports==__NOEDITSECTION__
===Link relationship subreports===__NOEDITSECTION__
In addition to the Location relationship, the main items in {{IMSMANG}} can also be linked with one another during the reconciliation process. This is how, for example, Activities are linked with Land in the {{IMSMANG}} database. Accidents, land, activities, educations, assistances, QMs, and victims may be related to one another via ''links''. For example, a victim may be associated to an accident in a particular land. If these relationships are known, IMSMA users may define these links while reconciling the Data Entry Form. This special relationship can also be modeled in iReport using a report and subreport (s).
The process for creating a report on an item and its linked items is similar to the process for creating a report on items with a Location relationship. The item in the main report is the primary item for which you would like to find linked items. The sub-report subreport would return the records for the particular item that is linked to the primary item. The key difference is the query used in the sub-reportsubreport.
To create a subreport using the link relationship:
*Step 1: Create a main report for an object with geospatial info
*Step 2: Create a GeospatialInfo subreport on the main report, i.e. a report using the GeospatialInfo datasource*Step 3: Create a Geopoint subreport on the GeospatialInfo report, i.e. a report using the Geopoint datasource
Step 1: Create a main report for an object with geospatial info
geospatialinfoguid IN $P{parametername}
This has the effect of limiting the Geospatial records to only those records whose guid is linked to the geospatialinfo of the main report. This is an example of nested reports, i.e. a main report, a subreport, and a sub-subreport.
===Other subreport relationships===__NOEDITSECTION__
6,632
edits

Navigation menu