Search code examples
ireport

conditional statements not working in expression editor


I want to check current month to many condition as below. so I take TextField ,edit its pattern to MM & in expression editor edit below code

new java.util.Date()>=4 && new java.util.Date() <= 7 ? "Q1" :  
new java.util.Date()>=8 && new java.util.Date() <=11  ? "Q2" : "Q3"

but it gives error

Error filling print... Error evaluating expression :      Source text : new java.util.Date()>=4 && new java.util.Date() <= 7 ? "Q1" : new java.util.Date()>=8 && new java.util.Date() <=11  ? "Q2" : "Q3" 
Setting up the file resolver..

but when I give expression like

new java.util.Date()== 4 ? "Q1" : "Q2"

It works fine.

Does iReport not able to resolve multiple conditions ? or should I give different TextField with single condition ?


Solution

  • Try using calendar instead.

    (Calendar.getInstance()).get(Calendar.MONTH)>=3 && (Calendar.getInstance()).get(Calendar.MONTH)>=6 ? "Q1" :
    (Calendar.getInstance()).get(Calendar.MONTH)>=7 && (Calendar.getInstance()).get(Calendar.MONTH)>=10  ? "Q2" : "Q3"