Crystal reports uses PreviousValue What is the equivalent in Jasper reports? - crystal-reports

Crystal reports uses PreviousValue (fld) What is the equivalent in Jasper reports?
I have searched online for possible answers but as yet not found anything. Any help would be appreciated.

There's no direct way to get the previous value of a field in JasperReports, but it can be done using two variables like this (the variable class should match the field type):
<variable name="PreviousFldValue" class="java.lang.String">
<variableExpression><![CDATA[$V{CurrentFldValue}]]></variableExpression>
</variable>
<variable name="CurrentFldValue" class="java.lang.String">
<variableExpression><![CDATA[$F{fld}]]></variableExpression>
</variable>
You would then use $V{PreviousFldValue} as the previous value of the field.
Note that the order in which the variables are declared is important, the solution relies on PreviousFldValue being calculated before CurrentFldValue.

Related

Jasper Report - Current Number of Group in Page

I have a PDF report split in several pages.
In every page I may have one or more groups. What I need is a count of current group number inside that page resetting at page change.
So the first group in page has 1, the next one 2 etc...
When I change a Page, the count has to restart from one.
I have found this good variable definition but it counts current group number for the entire report, ignoring the page.
<variable name="currentGroupNumber" class="java.lang.Integer" incrementType="Group" incrementGroup="GroupName">
<variableExpression><![CDATA[($V{GroupName_COUNT} == 1) ? $V{currentGroupNumber}+1 : $V{currentGroupNumber}]]></variableExpression>
<initialValueExpression><![CDATA[1]]></initialValueExpression>
</variable>
Any ideas?
The variable is missing resetType="Page"
Also, the variable looks a little more complex than it should, something like the following might do:
<variable name="currentGroupNumber" class="java.lang.Integer" calculation="Count" incrementType="Group" incrementGroup="GroupName" resetType="Page">
<variableExpression><![CDATA["foo"]]></variableExpression>
</variable>

Print when last row on table Jasper report

I have a report that needs to have an image printed only in the last row of the table of each page.
How can I create my print when expression?
Edit:
Sorry for my poor exemple.
until now, i created this variable
<variable name="rowsOnPage" class="java.lang.Integer">
<variableExpression><![CDATA[$V{rowsOnPage} + 1]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
and i try this print when expression:
$V{rowsOnPage} == $V{REPORT_COUNT}
But this expression print the image in each row of table.
As Petter says, providing an example of what you've tried and how close you've got so far would be helpful.
In the meantime my suggestion is that you add a max rowcount value to your SQL and return this as field in your JRXML as e.g. maxRowNum. With this you could then use a printWhen at the point when $V{REPORT_COUNT} == $F{maxRowNum}
This assumes you have access to the SQL part of your code and can play with this.

Can I change the value of a variable?

I'm new to JasperReports, but I kind of feel like I'm getting it. After all it is just another mark-up language.
My scenario is that I have a table of data, with the date and some other text columns, and I want to to display a subtotal for each section of the data based on a date. I am expecting zero, one, or many dates to be in the table.
I have a variable defined that calculates the sum of the rows, but I want to reset the sum to zero with each sub-group, is it possible?
Here is my Variable declaration:
<variable name="G_COUNT" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[(($F{ROW_NUMBER}.intValue() != 9)?$F{ITEM_COUNT}:new Integer(0))]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>
Is there a way I can use this variable, resetting to 0 when a new date is found, or am I using the wrong type to do what I want?
As a caveat, I am editing the .jrxml file in a text editor, not iReport.
What I was able to figure out from reading the dtd is that groups are available to trigger a reset event.
<variable name="G_COUNT" class="java.lang.Integer" calculation="Sum" resetType="Group" resetGroup="SubCalc">
<variableExpression><![CDATA[(($F{ROW_ORDINAL}.intValue() != 9)?$F{ITEM_COUNT}:new Integer(0))]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>
<group name="SubCalc">
<groupExpression><![CDATA[$F{ROW_ORDINAL} == 1]]></groupExpression>
</group>
So when the ROW_ORDINAL == 1 it triggers a reset event, which sets the value of G_COUNT to the initialValueExpression

JasperReport table column sum for page

I need TO add a column sum to column footer of table object for each page.
If I create variable and set sum aggregation function than sum value appear for full report. But I need sum column data for each page, not for full report.
Can anyone help me solve this problem?
This is not a solution for the jr:table component since it uses a subdataset where its not allowed to set resetType="Page", but using a subreport it can be used.
I don't think there is a work around in components (jr:table,jr:list) using a subdataset but would be happy If someone can prove me wrong
Solution using subreport
On your variable set resetType="Page"
es.
<variable name="var" class="java.lang.Double" resetType="Page" calculation="Sum"/>
....
</variable>
For more info on resetType see JRVariable API
On your textField set evaluationTime="Page"
es.
<textField evaluationTime="Page">
....
</textField>
For more info on evaluationTime see JRTextField API
In case of Dataset set resetType="Report"

Bypassing parameters in ireport 5.6.0

I created a simple report in i-report and i added a parameter on a field salary. Now every time i click on preview i get the parameter pop-up to filter. And if the value if not correct i get a blank page. Now that's exactly what i was trying to do. However i am wondering if there's a way to enter a certain value in the parameter box to display all records. Any idea if this possible and if yes how? Thank you.
WHERE EMPLOYEES."SALARY" = ${P1}
You need to change your query (lets imagine that SALARY is numeric, Double). to
WHERE EMPLOYEES."SALARY" = $P{parameter1} OR 0=$P{parameter1}
and define your parameter with a defaultValueExpression and set attribute isForPrompting="false"
<parameter name="parameter1" class="java.lang.Double" isForPrompting="false">
<defaultValueExpression><![CDATA[new java.lang.Double(0)]]></defaultValueExpression>
</parameter>
You will see no more prompt and display all data, if SALARY is of other class naturally you need to adjust the example accordingly.