eperrone Posted September 22, 2010 Share Posted September 22, 2010 Hey all, A bit new to this so I hope you will bear with me. I was trying to create some variables in iReport with groovy expressions. I have used groovy scripting for other purposes and I am confused about how the groovy must be formatted.I have a variable that I want to be equal to one of my database fields if another field is equal to 1 so this shorthand expression does the job:($F{SOURCE_WP} == 1.00) ? $F{PROJECT_PRICE} : 0.00Of course I have some other needs that require more complicated things like this, so can I write this same expression using if() { } else {} type syntax? I have used that in other grovy scripts but I always get errors in iReport when I try anything with if() in it...for example this... does not work it gives error:if($F{SOURCE_WP} == 1.00) { $F{PROJECT_PRICE}} else { 0.00}org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, calculator_id_work_plan_comparison_1285183287087_903939: 193: unexpected token: if @ line 193, column 40. 1 error at net.sf.jasperreports.compilers.JRGroovyCompiler.compileUnits(JRGroovyCompiler.java:101) Thanks for you time!Eric Link to comment Share on other sites More sharing options...
mdahlman Posted September 23, 2010 Share Posted September 23, 2010 Nope. You cannot write statements like that. You can only use expressions like you showed in your first example. This is true whether you are using Java or Groovy as the scripting language.If you need more complex things, you can nest expressions:($F{SOURCE_WP} == 1.00)? ( $F{PROJECT_PRICE} != null && $F{PROJECT_PRICE} > 100 ? "Woo Hoo" : "Bummer"): "Undecided"Regards,Matt Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now