Shaun Wingrin
asked on
Jasper iReports and conditional statement in field expression
Say, I want to padd the Integer CurrentInvNo with one or two leading zeros. This doesn't work. Any ideas?
$F{AccNo}+iif(F${CurrentIn vNo} > 9, iif($F{CurrentInvNo} > 99,'0','0'),'00')+$F{Curre ntInvNo}
$F{AccNo}+iif(F${CurrentIn
ASKER
Jasper won't complie this statement.
Compiling to file... C:\Documents and Settings\admin\My Documents\Voip SW\iReports\Savings Analysis Report & Management Invoice.jasper
Errors compiling C:\Documents and Settings\admin\My Documents\Voip SW\iReports\Savings Analysis Report & Management Invoice.jasper!
Compilation exceptions: co m.jasperso ft.ireport .designer. compiler.E rrorsColle ctor@998ba 2 net.sf.jasperreports.engin e.JRExcept ion: Error s were enc ountered w hen compil ing report expressio ns class f ile: org.codehaus.groovy.contro l.Multiple Compilatio nErrorsExc eption: st artup fail ed, calcul ator_Savin gs32Analys is32Report 323832Mana gement32In voice_1263 887050185_ 910313: 19 1: unexpec ted token: F @ line 191, colum n 181. 1 error at net.sf.jasperreport s.compiler s.JRGroovy Compiler.c ompileUnit s(JRGroovy Compiler.j ava:88) at net.sf.jasperreport s.engine.d esign.JRAb stractComp iler.compi leReport(J RAbstractC ompiler.ja va:188) at net.sf.jasperreport s.engine.J asperCompi leManager. compileRep ort(Jasper CompileMan ager.java: 215) at net.sf.jasperreport s.engine.J asperCompi leManager. compileRep ortToFile( JasperComp ileManager .java:131) at com.jaspersoft.irep ort.design er.compile r.IReportC ompiler.ru n(IReportC ompiler.ja va:510) at org.openide.util.Re questProce ssor$Task. run(Reques tProcessor .java:572) at org.openide.util.Re questProce ssor$Proce ssor.run(R equestProc essor.java :997)
Compilation running time: 1,329
Compiling to file... C:\Documents and Settings\admin\My Documents\Voip SW\iReports\Savings Analysis Report & Management Invoice.jasper
Errors compiling C:\Documents and Settings\admin\My Documents\Voip SW\iReports\Savings Analysis Report & Management Invoice.jasper!
Compilation exceptions: co
Compilation running time: 1,329
OK. In the middle of all of that, I see
unexpected token: F @ line 191, column 181
Meanwhile, looking at your code again, I noticed another apparent problem. After the first iif you have F${CurrentInvNo}, but in other places in the line, you have $F.
Still just guessing here, but maybe the error on token "F" is because you have F$ in that one spot, instead of $F. Or possibly it's the other way around, and each $F should be F$ . Either way, I'm guessing that they should all be the same.
James
unexpected token: F @ line 191, column 181
Meanwhile, looking at your code again, I noticed another apparent problem. After the first iif you have F${CurrentInvNo}, but in other places in the line, you have $F.
Still just guessing here, but maybe the error on token "F" is because you have F$ in that one spot, instead of $F. Or possibly it's the other way around, and each $F should be F$ . Either way, I'm guessing that they should all be the same.
James
ASKER
Good point but not. I'm trying to find if Jasper support iif and what correct syntax is....
Compiling to file... C:\Documents and Settings\admin\My Documents\Voip SW\iReports\Savings Analysis Report & Management Invoice.jasper
Compilation running time: 2,640!
Filling report...
Locale: English (South Africa)
Time zone: Default
Error filling print... Err or evaluat ing expres sion : Source text : $F{AccNo }+$F{Curre ntInvNo}+$ F{AccNo}+$ F{AccNo}+i if($F{Curr entInvNo} > 9, iif($ F{CurrentI nvNo} > 99 ,'','0'),' 00')+$F{Cu rrentInvNo }
net.sf.jasperreports.engin e.fill.JRE xpressionE valExcepti on: Error evaluating expressio n : Source text : $F{AccNo }+$F{Curre ntInvNo}+$ F{AccNo}+$ F{AccNo}+i if($F{Curr entInvNo} > 9, iif($ F{CurrentI nvNo} > 99 ,'','0'),' 00')+$F{Cu rrentInvNo } at net.sf.jasperreport s.engine.f ill.JREval uator.eval uate(JREva luator.jav a:193) at net.sf.jasperreport s.engine.f ill.JRCalc ulator.eva luate(JRCa lculator.j ava:570) at net.sf.jasperreport s.engine.f ill.JRCalc ulator.eva luate(JRCa lculator.j ava:538) at net.sf.jasperreport s.engine.f ill.JRFill Element.ev aluateExpr ession(JRF illElement .java:868) at net.sf.jasperreport s.engine.f ill.JRFill TextField. evaluateTe xt(JRFillT extField.j ava:368) at net.sf.jasperreport s.engine.f ill.JRFill TextField. evaluate(J RFillTextF ield.java: 353) at net.sf.jasperreport s.engine.f ill.JRFill ElementCon tainer.eva luate(JRFi llElementC ontainer.j ava:256) at net.sf.jasperreport s.engine.f ill.JRFill Band.evalu ate(JRFill Band.java: 482) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillBandN oOverflow( JRVertical Filler.jav a:421) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillPageH eader(JRVe rticalFill er.java:38 5) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillPageB reak(JRVer ticalFille r.java:191 3) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillColum nBreak(JRV erticalFil ler.java:1 940) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillDetai l(JRVertic alFiller.j ava:724) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillRepor tContent(J RVerticalF iller.java :272) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillRepor t(JRVertic alFiller.j ava:114) at net.sf.jasperreport s.engine.f ill.JRBase Filler.fil l(JRBaseFi ller.java: 923) at net.sf.jasperreport s.engine.f ill.JRBase Filler.fil l(JRBaseFi ller.java: 826) at net.sf.jasperreport s.engine.f ill.JRFill er.fillRep ort(JRFill er.java:59 ) at net.sf.jasperreport s.engine.J asperFillM anager.fil lReport(Ja sperFillMa nager.java :417) at net.sf.jasperreport s.engine.J asperFillM anager.fil lReport(Ja sperFillMa nager.java :247) at com.jaspersoft.irep ort.design er.compile r.IReportC ompiler.ru n(IReportC ompiler.ja va:858) at org.openide.util.Re questProce ssor$Task. run(Reques tProcessor .java:572) at org.openide.util.Re questProce ssor$Proce ssor.run(R equestProc essor.java :997) Caused by: groovy.lang.Mis singMethod Exception: No signat ure of met hod: Savin gs32Analys is32Report 323832Mana gement32In voice_1263 907738794_ 781923.iif () is appl icable for argument types: (ja va.lang.Bo olean, jav a.lang.Str ing, java. lang.Strin g) values: {false, " ", "0"} at org.codehaus.groovy .runtime.S criptBytec odeAdapter .unwrap(Sc riptByteco deAdapter. java:54) at org.codehaus.groovy .runtime.S criptBytec odeAdapter .unwrap(Sc riptByteco deAdapter. java:59) at org.codehaus.groovy .runtime.S criptBytec odeAdapter .invokeMet hodN(Scrip tBytecodeA dapter.jav a:169) at Savings32Analysis32 Report3238 32Manageme nt32Invoic e_12639077 38794_7819 23.invokeM ethod(calc ulator_Sav ings32Anal ysis32Repo rt323832Ma nagement32 Invoice_12 6390773879 4_781923) at org.codehaus.groovy .runtime.S criptBytec odeAdapter .invokeMet hodOnCurre ntN(Script BytecodeAd apter.java :82) at Savings32Analysis32 Report3238 32Manageme nt32Invoic e_12639077 38794_7819 23.evaluat e(calculat or_Savings 32Analysis 32Report32 3832Manage ment32Invo ice_126390 7738794_78 1923:191) at net.sf.jasperreport s.engine.f ill.JREval uator.eval uate(JREva luator.jav a:182) ... 22 more
Print not filled. Try to use an EmptyDataSource...
Compiling to file... C:\Documents and Settings\admin\My Documents\Voip SW\iReports\Savings Analysis Report & Management Invoice.jasper
Compilation running time: 2,640!
Filling report...
Locale: English (South Africa)
Time zone: Default
Error filling print... Err
net.sf.jasperreports.engin
Print not filled. Try to use an EmptyDataSource...
> Good point but not. I'm trying to find if Jasper
> support iif and what correct syntax is....
Oh well. It was a shot in the dark, although I really did think I might be on to something.
I've looked around jasperforge.org some, but haven't been able to find specific documentation on "formulas" like that (which I suppose may be your problem). If the underlying language is Java, then maybe that's really where you need to be looking to see if anything like iif is supported.
FWIW, looking at one of the Jasper examples, I see the following, which looks kind of similar to your line:
"There are " + String.valueOf($V{REPORT_C OUNT}) + " orders on this report, with a total freight of " + new DecimalFormat("0.00").form at($V{Frei ghtSumRepo rt}.double Value())
Maybe DecimalFormat is what you need to be looking at, in order to format CurrentInvNo to "000". Still just making guesses. :-)
The Jasper example that I was looking at is FirstJasper.jrxml . If it's included in the Jasper "package", then you may already have it, but I found it on:
http://jasperforge.org/website/jasperreportswebsite/trunk/samples.html?group_id=252
James
> support iif and what correct syntax is....
Oh well. It was a shot in the dark, although I really did think I might be on to something.
I've looked around jasperforge.org some, but haven't been able to find specific documentation on "formulas" like that (which I suppose may be your problem). If the underlying language is Java, then maybe that's really where you need to be looking to see if anything like iif is supported.
FWIW, looking at one of the Jasper examples, I see the following, which looks kind of similar to your line:
"There are " + String.valueOf($V{REPORT_C
Maybe DecimalFormat is what you need to be looking at, in order to format CurrentInvNo to "000". Still just making guesses. :-)
The Jasper example that I was looking at is FirstJasper.jrxml . If it's included in the Jasper "package", then you may already have it, but I found it on:
http://jasperforge.org/website/jasperreportswebsite/trunk/samples.html?group_id=252
James
ASKER
Tx 4 the effort, however the decimal point will look out of place as need Invoice NO: 013 for example.
Yes java could be the clue.... or someone who know iReports...
Yes java could be the clue.... or someone who know iReports...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tx. I did try but still not. Asking moderator.
Error filling print... Err or evaluat ing expres sion : Source text : $F{AccNo }+$F{Curre ntInvNo}+$ F{AccNo}+$ F{AccNo}+D ecimalForm at("000"). format($F{ CurrentInv No})
net.sf.jasperreports.engin e.fill.JRE xpressionE valExcepti on: Error evaluating expressio n : Source text : $F{AccNo }+$F{Curre ntInvNo}+$ F{AccNo}+$ F{AccNo}+D ecimalForm at("000"). format($F{ CurrentInv No}) at net.sf.jasperreport s.engine.f ill.JREval uator.eval uate(JREva luator.jav a:193) at net.sf.jasperreport s.engine.f ill.JRCalc ulator.eva luate(JRCa lculator.j ava:570) at net.sf.jasperreport s.engine.f ill.JRCalc ulator.eva luate(JRCa lculator.j ava:538) at net.sf.jasperreport s.engine.f ill.JRFill Element.ev aluateExpr ession(JRF illElement .java:868) at net.sf.jasperreport s.engine.f ill.JRFill TextField. evaluateTe xt(JRFillT extField.j ava:368) at net.sf.jasperreport s.engine.f ill.JRFill TextField. evaluate(J RFillTextF ield.java: 353) at net.sf.jasperreport s.engine.f ill.JRFill ElementCon tainer.eva luate(JRFi llElementC ontainer.j ava:256) at net.sf.jasperreport s.engine.f ill.JRFill Band.evalu ate(JRFill Band.java: 482) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillBandN oOverflow( JRVertical Filler.jav a:421) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillPageH eader(JRVe rticalFill er.java:38 5) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillPageB reak(JRVer ticalFille r.java:191 3) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillColum nBreak(JRV erticalFil ler.java:1 940) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillDetai l(JRVertic alFiller.j ava:724) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillRepor tContent(J RVerticalF iller.java :272) at net.sf.jasperreport s.engine.f ill.JRVert icalFiller .fillRepor t(JRVertic alFiller.j ava:114) at net.sf.jasperreport s.engine.f ill.JRBase Filler.fil l(JRBaseFi ller.java: 923) at net.sf.jasperreport s.engine.f ill.JRBase Filler.fil l(JRBaseFi ller.java: 826) at net.sf.jasperreport s.engine.f ill.JRFill er.fillRep ort(JRFill er.java:59 ) at net.sf.jasperreport s.engine.J asperFillM anager.fil lReport(Ja sperFillMa nager.java :417) at net.sf.jasperreport s.engine.J asperFillM anager.fil lReport(Ja sperFillMa nager.java :247) at com.jaspersoft.irep ort.design er.compile r.IReportC ompiler.ru n(IReportC ompiler.ja va:858) at org.openide.util.Re questProce ssor$Task. run(Reques tProcessor .java:572) at org.openide.util.Re questProce ssor$Proce ssor.run(R equestProc essor.java :997) Caused by: groovy.lang.Mis singMethod Exception: No signat ure of met hod: Savin gs32Analys is32Report 323832Mana gement32In voice_1263 971210466_ 105582.Dec imalFormat () is appl icable for argument types: (ja va.lang.St ring) valu es: {"000" } at org.codehaus.groovy .runtime.S criptBytec odeAdapter .unwrap(Sc riptByteco deAdapter. java:54) at org.codehaus.groovy .runtime.S criptBytec odeAdapter .unwrap(Sc riptByteco deAdapter. java:59) at org.codehaus.groovy .runtime.S criptBytec odeAdapter .invokeMet hodN(Scrip tBytecodeA dapter.jav a:169) at Savings32Analysis32 Report3238 32Manageme nt32Invoic e_12639712 10466_1055 82.invokeM ethod(calc ulator_Sav ings32Anal ysis32Repo rt323832Ma nagement32 Invoice_12 6397121046 6_105582) at org.codehaus.groovy .runtime.S criptBytec odeAdapter .invokeMet hodOnCurre ntN(Script BytecodeAd apter.java :82) at Savings32Analysis32 Report3238 32Manageme nt32Invoic e_12639712 10466_1055 82.evaluat e(calculat or_Savings 32Analysis 32Report32 3832Manage ment32Invo ice_126397 1210466_10 5582:191) at net.sf.jasperreport s.engine.f ill.JREval uator.eval uate(JREva luator.jav a:182) ... 22 more
Print not filled. Try to use an EmptyDataSource...
Error filling print... Err
net.sf.jasperreports.engin
Print not filled. Try to use an EmptyDataSource...
ASKER
Still don't know if iif (,,) is valid in Jasper
Having said that, and with the disclaimer that I don't know the first thing about Jasper iReports, I do see one error in your formula.
The middle iif should read:
iif($F{CurrentInvNo} > 99,'','0')
Which would make the formula:
$F{AccNo}+iif(F${CurrentIn
If you were getting a leading 0 on 3 digit numbers, that was probably why.
I'm assuming that CurrentInvNo is always positive. If not, you'd need separate tests for negative values, or you could use an absolute value function, if there is one, when testing the values.
James