2

Using text field value editor i add a text to the text field with a condition (note the if is constructed using the field editor of JasperSoft studio so the code IF(...) is autogenerated, i gave only the value "pippo" and "pluto")

"Some value" +IF(true,"pippo","pluto")

But it seems it don't work. I'm getting this error during calling the report from my code:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The method IF(boolean, String, String) is undefined for the type 

Any help will be appreciated

Alex K
  • 22,315
  • 19
  • 108
  • 236
Antimo
  • 460
  • 1
  • 8
  • 19
  • Where (at Java code or at Jaspersoft Studio) did you get this error? Your expression is absolutely right and should work at least for Groovy language (set for report) – Alex K Feb 15 '17 at 19:10
  • I get the error while trying to generate the report at runtime, expression was created in JasperSoft Studio, report compile fine but did not execute fine. @Alex may be a duplicate could be this (but i was not able to test the solution no valid maven artifact for jar involve too much work so i change strategy and use expression reported in my comment to solution) http://stackoverflow.com/questions/28243558/jasper-string-functions-method-undefined-error – Antimo Feb 16 '17 at 16:02
  • Duplicates: [JasperReports: CONCATENATE function not found](http://stackoverflow.com/q/19450214/876298) – Alex K Feb 16 '17 at 16:18
  • 2
    Try to add `net.sf.jasperreports:jasperreports-functions` artifact – Alex K Feb 16 '17 at 16:24
  • Thank you @AlexK i cannot test the suggestion because i used the other solution (the one in the answer) , anyway seems a good solution , i wasn't able to found this artifact googling around. – Antimo Feb 21 '17 at 14:58

2 Answers2

5

Try using ternary operator instead of IF like below

"Some value" + (value == true ? "pippo" : "pluto")

Hope this would help you out.

Viki888
  • 2,686
  • 2
  • 13
  • 16
  • 1
    Missing the == , anyway this save me hour of testing, this is a correct answer This code work for me: `($F{fieldInReport} == true ? "pippo" : "pluto")`. fieldInReport is a boolean field (damn apparently i tested same code yesterday and it did not work :)!). Thank you! – Antimo Feb 15 '17 at 11:55
0

You need to include jasperreports-functions in your build file. e.g: for gradle

implementation 'net.sf.jasperreports:jasperreports-functions:6.12.2'
Ruchira Nawarathna
  • 1,137
  • 17
  • 30