ballinascreen Posted May 29, 2012 Share Posted May 29, 2012 Folks,Consider the following scenario. I have a dataset which I'd lile to filter the contents of. The dataset query defines a call to a stored procedure which returns a resultset containing a small number of columns - one of which contains an 'id' value which I wish to filter on. I can already successfully filter the results using something along the lines of: $F{myIdField}.equals(1) || $F{myIdField}.equals(2) || ... and so on.However, I'd really like to pass in a list of filter ID's as a report parameter and perform the filtering like this:$P{MY_REPORT_PARAM_LIST}.contains($F{myIdField})where MY_PARAM_LIST is defined as type java.util.List and contains multiple ID's (in this case Integers) that I want to match on.But this doesn't seem to work and all records in my dataset are filtered out. As a test, I created a dummy Text Field on the title page of my report and added the following expression:$P{MY_REPORT_PARAM_LIST}.contains("1")which successfully returned the correct results based on input, i.e.:1,2,3,4 - true2,3,4,5 - falseSo, why does this seem to work as a simple text field expression, but not as a dataset filter expression.I even tried updating the dataset filter expression to this:$P{MY_REPORT_PARAM_LIST}.contains("1") and ran the report, passing in a list of 1,2,3 - so I would have expected this to evaluate to true and not filter any results - but everything was filtered as before.Product Version: Jaspersoft iReport Designer 4.5.1Java: 1.7.0_02; Java HotSpot Client VM 22.0-b10System: Windows 7 version 6.1 running on x86; Cp1252; en_US (ireport) Any ideas? Post Edited by ballinascreen at 05/29/2012 21:17 Link to comment Share on other sites More sharing options...
ballinascreen Posted May 30, 2012 Author Share Posted May 30, 2012 A little further testing seems to confirm that the report parameter value is not being passed to the filter expression of the dataset. For example, if I set the filter expression to:$P{MY_REPORT_PARAM_LIST} == nullall my records are displayed, that is, none are filtered because the MY_REPORT_PARAM_LIST appears to be null$P(MY_REPORT_PARAM_LIST} != nullall my records are now filtered outSo, why is the value of the report parameter seemingly not made available to dataset filter expressions but can be used elsewhere in the report - or am I missing something fundamental here? Link to comment Share on other sites More sharing options...
ballinascreen Posted May 30, 2012 Author Share Posted May 30, 2012 Further update:Seems like the following works instead:((ArrayList) $P{REPORT_PARAMETERS_MAP}.get( "MY_REPORT_PARAM_LIST" )).contains($F{myIdField}.toString())where I extract the list from the built-in report parameter REPORT_PARAMETERS_MAPStill doesn't explain why the value of my dedicated report parameter is not made available to the dataset filter expression, but I'm happy at least that I can get the filter working another way. Link to comment Share on other sites More sharing options...
sadakar Posted October 7, 2015 Share Posted October 7, 2015 Hi,Thank you very much for this solution. It helped me a lot but struck with a small issue.If I don't pass any value from input I need to get all the records.How can I give OR condition combining with above condition ? or How can I get all the values if I dont pass any thing. 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