2006 JR Open Discussion Posted August 22, 2006 Share Posted August 22, 2006 By: Shireesh Anjal - anjalshireesh Ignoring records based on condition 2006-03-30 00:02Hi, 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:30use 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:30use 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:38Hi, 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 Link to comment Share on other sites More sharing options...
yuv Posted September 18, 2007 Share Posted September 18, 2007 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 Link to comment Share on other sites More sharing options...
lucianc Posted September 18, 2007 Share Posted September 18, 2007 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 Link to comment Share on other sites More sharing options...
yuv Posted September 19, 2007 Share Posted September 19, 2007 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 Link to comment Share on other sites More sharing options...
lucianc Posted September 19, 2007 Share Posted September 19, 2007 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 iReport forum. Regards,Lucian Link to comment Share on other sites More sharing options...
yuv Posted September 19, 2007 Share Posted September 19, 2007 ahh ok..thnx Lucian.. Link to comment Share on other sites More sharing options...
yuv Posted September 19, 2007 Share Posted September 19, 2007 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now