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

How to use conditional clause on a field in Jasper report to get values?


daad.madhusudan
Go to solution Solved by sanbez,

Recommended Posts

I am working on a jasper report in that I am using a field "RACE_CODE" which contains values like 'abc','lmn','pqr','xyz'. For one person there can be multiple RACE_CODE assigned to it.

 

So I want the output in term of four digits like:

 

If a person have RACE_CODE 'abc' and 'xyz' then it should display '1001' and so on.

 

I can use conditional statement like:

 

    $F{RACE_CODE} == 'abc' && $F{RACE_CODE} == 'xyz' ? 

    '1001' : ($F{RACE_CODE} == 'abc' ? '1000' : so on

 

But this is not a feasible way because for four digits I will be having 12 combinations.

 

Is there any other way in which I can achieve this? Please help to solve this.

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Thanks @sanbez for your response :).

Yeah you are right. One person can have multiple race codes. In my case there are 7 race codes and one person can have many race codes from these seven values. So for this, I want seven digit binary representation. 

Want i want is:

IF RACE_CODE CONTAINS (abc,lmn)

then display 1100000

if RACE_CODE CONTAINS (abc,xyz)

display 1000001

I am taking some test values here like abc,lmn,xyz for demo.

 

 

 

Link to comment
Share on other sites

  • Solution

Why 7 digids? You start only with 4 :) I guess that one of the possible values of $F{RACE_CODE} is "abcxyz" (you don't write example of data). Is it right? In this case you can use expression like this (java code example):

  public static void main(String[] args) {    String RACE_CODE = "abcxyz";       System.out.println(RACE_CODE.indexOf("abc") == -1 ? "0" : "1" + (RACE_CODE.indexOf("lmn") == -1 ? "0" : "1") + (RACE_CODE.indexOf("pqr") == -1 ? "0" : "1") + (RACE_CODE.indexOf("xyz") == -1 ? "0" : "1"));     }[/code]

 

Link to comment
Share on other sites

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...