Ignoring records based on condition

By: Shireesh Anjal - anjalshireesh
Ignoring records based on condition
2006-03-30 00:02
Hi,

We have a requirement wherein the report engine should be able to ignore certain records based on certain criteria. (This criteria can be set as an expression that returns a Boolean value - true or false).

If the value of the given expression is true, then that particular record (row from the data source) should be ignored and next row should be fetched and evaluated. e.g. Ignore all rows where value of the field partTranType is "C". (This is just a simple example, there can be more complex conditions).

The expression can contain variables, fields, parameters and constant values.

Please let me know how this can be achieved with JasperReports.

Thanks and regards,
Shireesh Anjal


By: jasperkan - jasperkannan
RE: Ignoring records based on condition
2006-03-31 14:30
use the flag value ie partTanType='C' set the PrintWhenExpression expression to true for the entire field. so if the field value doesnt match entire row gets skipped.




By: jasperkan - jasperkannan
RE: Ignoring records based on condition
2006-03-31 14:30
use the flag value ie partTanType='C' set the PrintWhenExpression expression to true for the entire fields . so if the field value doesnt match entire row gets skipped.




By: Shireesh Anjal - anjalshireesh
RE: Ignoring records based on condition
2006-04-03 10:38
Hi,

Setting printWhenExpression will ensure that the record will not be printed on the report. However detail evaluation will still happen for these records, and hence the evaluation of all variables will also happen.

My requirement is that whenever the predefined condition is true, the current row should be ignored and none of the variables should be evaluated for this row. The next row should be fetched immediately and the detail evaluation should happen on this row (if the condition is not true for this row).

Let me give a small example to explain this.
Let us say the data coming from the data source is as follows:
================
emp_no salary
1001 20000
1002 30000
1003 40000
1004 50000
1005 10000
1006 23000
================
In the report, we need to print all employees whose salary is greater than 25000, and also the sum of salaries of such employess. i.e. the report should look like:

========================================
Employees having salary more than 25000:

emp_no salary
================
1002 30000
1003 40000
1004 50000
================
Total 120000
========================================

For calculating the total of salaries, we need to define a variable (sum_sal) of type sum and expression as $F{salary}

If we use printWhenExpression in the detail band to print only those rows where salary is more than 25000, the number of records will be correct, however the variable sum_sal will still contain the total of all the records, which will be 170000.

I know that we can still manage by putting a ternary operator in the variable expression - something like:
$F{salary} > 25000 ? $F{salary} : new BigDecimal(0)

However this will become really tedious and user unfriendly if there are too many variables in a report. Hence we need a mechanism wherein the user can specify a condition, which being true, those records coming from data source will be ignored - not just while printing the detail band, but also for variable evaluation.

It is true that such situations can be best handled by not sending such data from the data source, however it may not always be possible. e.g. Our data source is a custom data source that provides the data from a flat file. And since it (the custom data source) can not access variables/parameters from the report, there is no way it can filter data based on a user specified condition.

Probably we need some tag in the JRXML file where user can specify a condition for ignoring records. When this condition evaluates true, the present record should be discarded and the next one should be fetched before any variable evaluation happens. Or at least some API function that I can invoke from my scriptlet (inside beforeDetailEval) so as to move to the next record without evaluating any variables.

Thanks and regards,
Shireesh Anjal
2006 JR Open Discussion's picture
Joined: Aug 17 2006 - 4:00am
Last seen: 17 years 1 month ago

6 Answers:

hi shreerish ..did u find a solution..?
i am in similar kind of problem..
neverthless i do think setting expression for each field [also details part fields / subreport ] shd provide the solution...offcourse it will process tht record unnecessoriry..

let me know if u applied any fix to this prblm...

Thnx,
Yuv
yuv's picture
yuv
167
Joined: Jul 13 2007 - 12:51am
Last seen: 16 years 2 months ago
JR 1.2.5 introduced filter expressions that can be used to skip records produced by the data source. Check the "csvdatasource" sample to see an working example.

HTH,
Lucian
lucianc's picture
87115
Joined: Jul 17 2006 - 1:10am
Last seen: 11 hours 59 min ago
hi lucian ..
can you plz provide me link..where i can find this..
bye d way i am developing report thr Ireport 1.3...
but i dont see any option from where i can set FilterExpressions..
can you help..

-Yuv
yuv's picture
yuv
167
Joined: Jul 13 2007 - 12:51am
Last seen: 16 years 2 months ago
At the top of the list of topics of this forum there is a topic called "READ THIS before creating a NEW TOPIC". Read it to find out where you can get the JasperReports sample from.

If you have questions regarding iReport, please use the [url=http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&f... forum.

Regards,
Lucian
lucianc's picture
87115
Joined: Jul 17 2006 - 1:10am
Last seen: 11 hours 59 min ago
ahh ok..thnx Lucian..
yuv's picture
yuv
167
Joined: Jul 13 2007 - 12:51am
Last seen: 16 years 2 months ago
hello,
i found <filterExpression> to filter the data. It works fine ..i have tested it for my report.
However when i use PAGE_NUMBER varible in same expression...i think it filters all records ..only single page report generated.. :(
My requirement is to print specific records(depends on single field value in my record)..on Even Page only..
[i also have reset page after keygroup change enabled]

so i want to check in filter expression =>
if field from record is with some specific value and page number is even then only print this record..
Is it possible../
any alternate way available..?

-Yuvaraj
yuv's picture
yuv
167
Joined: Jul 13 2007 - 12:51am
Last seen: 16 years 2 months ago
Feedback