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

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.
daad.madhusudan's picture
Joined: Mar 13 2015 - 4:36am
Last seen: 7 years 1 month ago

$F{RACE_CODE} == 'abc' && $F{RACE_CODE} == 'xyz' always false. 
>>For one person there can be multiple RACE_CODE assigned to it.
Report field have only one value.

Question is unclear

sanbez - 8 years 2 months ago

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.

 

 

 

daad.madhusudan - 8 years 2 months ago

1 Answer:

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"));   
  }

sanbez's picture
7132
Joined: Jan 11 2011 - 2:06am
Last seen: 2 years 11 months ago
Feedback