Jump to content
We've recently updated our Privacy Statement, available here ×

How to check null in a Multi-Select/ Collection Parameter.


famykhan4u
Go to solution Solved by famykhan4u,

Recommended Posts

Hi folks,

I have a Multi-Select input control(i.e. param_prj_id) on the Jasper Server which is having multiple Project ID's via Query. I created a collection parameter with the same code(i.e. param_prj_id) in the Jasper Report.

Everything is working fine when the values are passed. But I am unable to check for null when no value is passed in the Multi-Select (Since the $X{IN} converts the query to 1=1 if no values are passed).

I want to explicitly check for null in this Multi- Select input control. (i.e. if no id's are selected - display a message).

It would be great if someone helps me with this.

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

This is the default functionality of multi-select, i.e, if no values are passed through the input control, it considers the scenario as all are values selected.

So if you want to display a message, create a parameter (Lets say $P{test} ) with an expression like below;


$P{param_prj_id} == null ? "1" :"0"

Using this parameter, display a band saying "No values selected" (as per your requirement) and use print when condition for that band using $P{test}

Regards,
KKriplani

Link to comment
Share on other sites

Hello KKriplani,
 
Thank you for the quick reponse.
 
I tried using $P{param_prj_id} == null ? "1" :"0", but the result is always 1 irrespective of the values i pass in the collection parameter.
 
Always resulting that the parameter is null.
 
Maybe it has something to do with the evaluation time, the parameters are evaluated before the report execution. I did try to find the evaluation setting in properties but Parameters doesn't have them.
 
Also if i take a plain text field & put the same expression in the text field it will work just fine.
 
JRXML Code :
<parameter name="param_prj_id" class="java.util.Collection" nestedType="java.lang.Integer"/>
 
<parameter name="is_null" class="java.lang.String" isForPrompting="false">
       <defaultValueExpression><![CDATA[$P{param_prj_id} == null ? "1" :"0"]]></defaultValueExpression>
</parameter>

 

Link to comment
Share on other sites

  • Solution
Hi KKriplani,

 

The above default expression evaluated to be "null".

 

I was however able to achieve the desired result in the sql query by writing the below code to identify null in multi-select parameter:

 

--The Where condition will check if the Multi-Select Parameter isNull

Select 1 Data from Dual

where $X{IN, 0, param_prj_id} 

 

UNION ALL

 

--The Where condition will check if the Multi-Select Parameter isNotNull

Select 2 Data from Dual

where $X{NOTIN, 0, param_prj_id} 

 

If I get Null in Multi-Select I simply set the data variable to 1(lets say - test) and use this 'test' variable on a band as display expression. when $F{test} == 1.

 

The actual query is much more complicated, but this exactly what i needed :)

 

Thanks for all your help :)

Link to comment
Share on other sites

  • 6 months later...

@KKriplani, your suggestion of using the below worked fine with a mention here -  $P{Param_Prj_Id}.isEmpty()?1:0. The new param that I used was an integer and hence assigned 1 and 0 integer values. There was an evaluation error with the new param being string. Anyway, your suggestion saved my day! Cheers!

 

 

Link to comment
Share on other sites

  • 2 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...