Creating A Multi-Select Parameter in Jaspersoft Studio
In this post, I will take you through the step by step procedure to create a Multi Select Parameter in Jaspersoft Studio.
This Method would just create a parameter Value where you have to Manually add multiple values which will then be passed on the SQL to fetch data. There will not be a value list appearing for this parameter. (If you want that functionality, it is possible only at the JasperServer level).
Lets Start.
1) Create Report with a simple SQL Query as Below.
2) Report Layout can be as per your specification. I have created it as below.
3) When I preview the Report It looks like this.
4) On the Outline section, Right Click on the Parameter section and select “Create Parameter”.
5) Name the Parameter as “P_COUNTRY” and select the Class as “Collection – java.util”
6) and Set is prompting to true by checking the check box.(By default it will be checked, so change it only when you need the parameter to be hidden.
7) Once the parameter is created, go to the Data Query section to edit the SQL Query to pass the Parameter Value. Use “$X{IN, v_name, MyParam}” code in the query as shown below.
8) Now when you preview the report, the report will ask you to provide the parameter value.
9) Select the browse button as shown in above figure (Button next to “No Elements”) and a window will pop up as below.
10) Click Add button and add your parameter Values. (Here the list will not populate as in Jaspersoft Studio there is no facility to generate this list. But if you publsih this report to Jaspersoft Server, we can create Multiselect Input Control and link it to P_COUNTRY parameter, there we can create a list value to appear for user selection.)
11) Now Click the Start Button below, to run the report.
12) And the Result will be the data related to your selection.
In my upcoming blog I will Publish this report to server and explain how to create Input control and Run the same report from server.
Thanks – I get the message “The report requires that you specify the value for some parameters before running it” after Click the green Arrow in Step 11. I have followed your steps to the Letter beforehand. Do you know if there is something additional I need to do?
Hi Dylan,
The error means that you have not provided any parameter value. you have to manually add values to the parameter list.
Thanks,
Rajesh S
I got the message like this, eventhough I have added the parameters.
The report requires that you specify the value for some parameters before running it.
Plss Reply
Thanks – How can i set a default value expression for my collection? (“Value1″,”Value2”) etc. I have tried a lot of initialization but when i preview my report i have zero elements in my list. Thanks in advance
Very, very , thank you , I searched everywhere and nothing helped me . Your tutorial was simple and saved my skin , thank you again!
Hi Rajesh,
I am using MongoDB as a datasource. Now the problem is, i have 3 filters and condition is that user may or may not select any value from any filter. If user selects any value from a filter than that value should be used for that filter and for other filter all values should be taken by default.
You may refer my question at http://stackoverflow.com/questions/29693999/put-condition-between-multiple-multi-select-filters-in-jasper-reports?noredirect=1#comment47588096_29693999
Hi Rajesh
Is there a link to “In my upcoming blog I will Publish this report to server and explain how to create Input control and Run the same report from server. “?
Kind regards
Martin