group expression in jasper reports - jasper-reports

I've a report which has a has 5 columns on each page and I have a group defined which shows columns related to
A | B | C | D | E - main column
X | Y | Z - group - A is the key
I have my query ORDER BY A, but when it is displayed it doesn't print the results in next page if A is changed.
Following is how I have a group defined.
<group name="A" isResetPageNumber="true" >
<groupExpression><![CDATA[$F{A}]]></groupExpression>
<groupHeader>
<band/>
</groupHeader>
<groupFooter>
<band/>
</groupFooter>
</group>
does A need to be part of the group?

Use:
<group name="A" isStartNewPage="true" isReprintHeaderOnEachPage="true"
isResetPageNumber="false" >

I answered my own question. I had to add A with X, Y, and Z in order for group to work.

Related

How to create sub table of contents in a specific section of band report in jasper?

I need to design a report using jasper reports which has main table of content for the whole report and a sub table of content at the starting of a specific section. The problem that it is not valid to use nested books. So is there another way to do that?
I have 3 parts in the report. The first and the third parts are table of contents. When the second part contains a bookmarkLevel, both table of contents don't work properly. Whenever I remove the bookmarkLeve, both table of contents work properly.
<group name="dummy">
<groupExpression><![CDATA[1]]></groupExpression>
<groupHeader>
<part evaluationTime="Report" uuid="1fadcc2f-31c1-49be-bd52-f8b69e38cd83">
<property name="net.sf.jasperreports.bookmarks.data.source.parameter" value="REPORT_DATA_SOURCE"/>
<partNameExpression><![CDATA["Table of Contents"]]></partNameExpression>
<p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd" usingCache="true">
<subreportExpression><![CDATA["TOCPart.jasper"]]></subreportExpression>
</p:subreportPart>
</part>
<part uuid="3f63c482-39b2-43f1-a623-15fb046605a5">
<partNameExpression><![CDATA["Overview"]]></partNameExpression>
<p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">
<subreportParameter name="REPORT_CONNECTION">
<subreportParameterExpression><![CDATA[$P{REPORT_CONNECTION}]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA["OrdersReport.jasper"]]></subreportExpression>
</p:subreportPart>
</part>
<part evaluationTime="Report" uuid="1fadcc2f-31c1-49be-bd52-f8b69e38cd84">
<property name="net.sf.jasperreports.bookmarks.data.source.parameter" value="REPORT_DATA_SOURCE"/>
<partNameExpression><![CDATA["Table of Contents2"]]></partNameExpression>
<p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">
<subreportExpression><![CDATA["TOCPart2.jasper"]]></subreportExpression>
</p:subreportPart>
</part>
</groupHeader>
</group>

Jasper CVC Component with Sub-Dataset

I'm working on CVC component in Jasper Studio. It is working fine with the "ReportMainDataset" but when I'm using the "Sub Dataset" it is not plotting.
Just wanted to know does CVC component works with "Sub Dataset" or not. If works, guide me how can I achieve this.
The tag for indicating the dataset is <cvData>
Example
subdataset
<subDataset name="Dataset1" uuid="03d50d7f-1b96-486a-ac64-7d2c6e440433">
<queryString>
<![CDATA[select count(*) t, shipcountry, shipcity from orders group by shipcountry, shipcity order by shipcountry, shipcity]]>
</queryString>
<field name="SHIPCOUNTRY" class="java.lang.String"/>
<field name="T" class="java.lang.Long"/>
<field name="SHIPCITY" class="java.lang.String"/>
</subDataset>
component
<cvc:customvisualization xmlns:cvc="http://www.jaspersoft.com/cvcomponent" xsi:schemaLocation="http://www.jaspersoft.com/cvcomponent http://www.jaspersoft.com/cvcomponent/component.xsd" evaluationTime="Report" onErrorType="Icon">
<cvc:itemProperty name="script" value="d3_zoomable_circle_packing.min.js"/>
<cvc:itemProperty name="css" value="d3_zoomable_circle_packing.css"/>
<cvc:cvData>
<dataset>
<datasetRun subDataset="Dataset1" uuid="bd23d50f-2149-4985-a0ac-883505172688">
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
<cvc:item>
<cvc:itemProperty name="category">
<valueExpression><![CDATA[$F{SHIPCOUNTRY}]]></valueExpression>
</cvc:itemProperty>
<cvc:itemProperty name="subcategory">
<valueExpression><![CDATA[$F{SHIPCITY}]]></valueExpression>
</cvc:itemProperty>
<cvc:itemProperty name="value">
<valueExpression><![CDATA[$F{T}]]></valueExpression>
</cvc:itemProperty>
</cvc:item>
</cvc:cvData>
</cvc:customvisualization>
EDIT: As #dada67 comment it does not seem to work properly, I have also test it with sample d3_zoomable_cricle_packing.jrxml without success, this is the bug issue
The work around, create a subreport!

jasper report passing parameter from list index

I got a scenario where I need to pass jasper report parameter value from a list using index.
I have the following query executed in the jasper report, with the following parameters defined.
<parameter name="clientServiceIds" class="java.util.Collection"/>
<parameter name="trafficPeriod" class="java.util.Collection"/>
<parameter name="transactionType" class="java.util.Collection"/>
<parameter name="transactionStatus" class="java.util.Collection"/>
<parameter name="roamingPartners" class="java.util.Collection"/>
<parameter name="ages" class="java.util.Collection"/>
SELECT
CLIENT_CODE,
PARTNER_ORG,
PARTNER_CODE,
SERVICE_TYPE,
TP_ID,
TRAFFIC_PERIOD,
SETTLEMENT_TYPE,
SDR_NET,
TRAN_CURR_NET,
TRAN_CURRENCY_ID,
DUE_DATE,
TRANSACTION_TYPE,
STATUS,
NOTE_ID,
AGE
FROM vw_transaction_search
WHERE $X{IN, client_service_id, clientServiceIds}
AND $X{IN, PARTNER_SERVICE_ID, roamingPartners}
AND $X{IN, traffic_period, trafficPeriod}
AND $X{IN, transaction_type, transactionType}
AND $X{IN, status_id, transactionStatus}
AND AGE BETWEEN $P{param1} AND $P{param2}
Here ages is a list which I am passing to the report, which contains two values at index 0 and index 1. All parameters (paramValueMap) I am getting from an external system which i cannot modify,
JasperFillManager.fillReport(jasperReport, paramValueMap, connection);
so I am looking for a way to pass parameters param1 and param2 in my Jasper report SQL from my Collection ages, something like param1=ages.get(0) and param2=ages.get(1), so the SQL will be something like
...AND $X{IN, status_id, transactionStatus}
AGE BETWEEN $P{ages.get(0)} AND $P{ages.get(1)}
is there any way possible to achieve this?
I was able to crack this down by adding two additional parameters age1 & age2 and passing the value to the added parameters from the list here are the details.
<parameter name="trafficPeriod" class="java.util.Collection"/>
<parameter name="transactionType" class="java.util.Collection"/>
<parameter name="transactionStatus" class="java.util.Collection"/>
<parameter name="roamingPartners" class="java.util.Collection"/>
<parameter name="age" class="java.util.List" isForPrompting="false"/>
<parameter name="age1" class="java.lang.Integer" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{age}.get(0)]]></defaultValueExpression>
</parameter>
<parameter name="age2" class="java.lang.Integer" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{age}.get(1)]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
CLIENT_CODE,
PARTNER_ORG,
PARTNER_CODE,
SERVICE_TYPE,
TP_ID,
TRAFFIC_PERIOD,
SETTLEMENT_TYPE,
SDR_NET,
TRAN_CURR_NET,
TRAN_CURRENCY_ID,
DUE_DATE,
TRANSACTION_TYPE,
STATUS,
NOTE_ID,
AGE
FROM vw_transaction_search
WHERE $X{IN, client_service_id, clientServiceIds}
AND $X{IN, PARTNER_SERVICE_ID, roamingPartners}
AND $X{IN, traffic_period, trafficPeriod}
AND $X{IN, transaction_type, transactionType}
AND $X{IN, status_id, transactionStatus}
AND AGE BETWEEN $P{age1} AND $P{age2}
ORDER BY client_code,
partner_code,
traffic_period,
age]]>
</queryString>

Page Break error new page

Print a set of invoices in PDF, I put Page Break $V{PAGE_COUNT}==16 and a group to break invoice number. All OK, but if the invoice rows = 16 the group total invoice print in a new page. Any ideas?
<group name="documento" isResetPageNumber="true" footerPosition="ForceAtBottom"><groupExpression><numero fattura></groupExpression><groupFooter> <band height="230" splitType="Immediate"><textField><reportElement> totali fattura.....</band></groupFooter></group> <pageHeader><band height="350" splitType="Stretch"> <textField><reportElement><textField><reportElement>testata fattura</band></pageHeader><detail><band height="16" splitType="Stretch"><break> <reportElement><printWhenExpression><![CDATA[$V{PAGE‌​_COUNT}==16]]></printWhenExpression> </reportElement></break></band></detail></ja‌​sperReport>

How to create user defined formula for user defined field

I have created one JasperReports report in iReport 4.5.0.
Here i have created one expression as:
<textField pattern="###0.0;-###0.0">
<reportElement x="248" y="3" width="46" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[( $F{salesdetails_LessWeight} == 0 ? $F{salesdetails_Weight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) : $F{salesdetails_WithPlasticWeight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) )]]></textFieldExpression>
</textField>
Here I need the sum(total) of this text field created above ,
How to do that?
In this case you would simply create a variable with the same expression, but with a operation of "SUM". You can change the reset type to specify a group or simply for the whole report.
You can then use that variable in the Text Field element, with the execution time of Report/Group/Now depending on your needs.
<variable name="SOSUM" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{salesdetails_LessWeight} == 0 ? $F{salesdetails_Weight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) : $F{salesdetails_WithPlasticWeight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) ]]></variableExpression>
</variable>