Replace month with a roman numeral
If you want to replace the month with a roman numeral in iReport, use the following expression:
"Date: "+($F{Start_Date_(Day)}==null?"":$F{Start_Date_(Day)}+".").toString()+ ($F{Start_Date_(Month)}+".").toString().replace("10","X").replace("11","XI").replace("12","XII").replace("1","I").replace("2","II").replace("3","III").replace("4","IV").replace("5","V").replace("6","VI").replace("7","VII").replace("8","VIII").replace("9","IX")+($F{Start_Date_(Year)}==null?"":$F{Start_Date_(Year)}).toString()
Making dates display full month names instead of numbers
($F{Collection_Date_(Day)}==null?"":$F{Collection_Date_(Day)}+"
").toString()+($F{Collection_Date_(Month)}==null?"":$F{Collection_Date_(Month)}+"
").toString().replace("10","October").replace("11","November").replace("12","December").replace
("1","January").replace("2","February").replace("3","March").replace("4","April").replace("5","May
").replace("6","June").replace("7","July").replace("8","August").replace("9","September")
+($F{Collection_Date_(Year)}==null?"":$F{Collection_Date_(Year)}+"").toString()
Making dates have extra zeros
For example, you date looks like this 2012/7/9 and you want it to look like 2012/07/09. Note that
the format is year/month/day here, you can switch it around as you wish. Use this expression:
"Date: " + ($F{Date_(Year)}==null?"":$F{Date_(Year)}+"").toString()
+($F{Date_(Month)}==null?"":"/"+(($F{Date_(Month)}+"").toString().length() == 2 ?
($F{Date_(Month)}+"").toString(): "0" + $F{Date_(Month)}+"")).toString() +
($F{Date_(Day)}==null?"":"/" + (($F{Date_(Day)}+"").toString().length() == 2 ?
($F{Date_(Day)}+"").toString(): "0" + $F{Date_(Day)}+"")).toString()
Display date as “Month Day, Year”
This would display as something like November 19, 2000
($F{Date_(Month)}==null?"":$F{Date_(Month)}+" ").toString().replace("10","October").replace("11","November").replace("12","December").replace("1","January").replace("2","February").replace("3","March").replace("4","April").replace("5","May").replace("6","June").replace("7","July").replace("8","August").replace("9","September")+($F{Date_(Day)}==null?"":$F{Date_(Day)}+", ").toString()+($F{Date_(Year)}==null?"":$F{Date_(Year)}+" ").toString()
Getting rid of extra punctuation when fields are null
For example, you don’t want a report to look like ‘South America, Paraguay , , , ‘ if the rest of
some of the fields in the middle of the expression are null. To only make extra punctuation or
even words show up only when there is information in the field, format like this:
($F{Continent}==null?"":$F{Continent})+($F{Country}==null?"":", " +
$F{Country})+($F{State}==null?"":", " + $F{State})+($F{County}==null?"":", " +
$F{County})+($F{Locality_Name}==null?"":", " + $F{Locality_Name})+($F{Latitude1}==null?"":",
" + $F{Latitude1}+"°").toString()+($F{Longitude1}==null?"":", " + $F{Longitude1}+"°").toString()
Insert your own fields or do whatever you want, but this should work perfectly.
Jaspersoft Studio
Cataloged Date display full month names instead of numbers
($F{1.collectionobject.catalogedDateNumericDay}==null?"":$F{1.collectionobject.catalogedDateNumericDay}+"
").toString()+($F{1.collectionobject.catalogedDateNumericMonth}==null?"":$F{1.collectionobject.catalogedDateNumericMonth}+"
").toString().replace("10","October").replace("11","November").replace("12","December").replace
("1","January").replace("2","February").replace("3","March").replace("4","April").replace("5","May
").replace("6","June").replace("7","July").replace("8","August").replace("9","September")
+($F{1.collectionobject.catalogedDateNumericYear}==null?"":$F{1.collectionobject.catalogedDateNumericYear}+"").toString()
Determined Date display full month names instead of numbers
($F{1,9-determinations.determination.determinedDateNumericDay}==null?"":$F{1,9-determinations.determination.determinedDateNumericDay}+" ").toString()+($F{1,9-determinations.determination.determinedDateNumericMonth}==null?"":$F{1,9-determinations.determination.determinedDateNumericMonth}+" ").toString().replace("10","October").replace("11","November").replace("12","December").replace
("1","January").replace("2","February").replace("3","March").replace("4","April").replace("5","May").replace("6","June").replace("7","July").replace("8","August").replace("9","September")
+($F{1,9-determinations.determination.determinedDateNumericYear}==null?"":""+$F{1,9-determinations.determination.determinedDateNumericYear}).toString()
Display nothing if empty or null
($F{1,5-cataloger.agent.cataloger} == null || $F{1,5-cataloger.agent.cataloger}.isEmpty() ? "" : "<br>"+"<b>"+"Cataloguer"+"</b>")
Replace value with another value
$F{1.collectionobject.text1} == null ? "" :
$F{1.collectionobject.text1}.equals("Extra Small") ? "XS" :
$F{1.collectionobject.text1}.equals("Small") ? "S" :
$F{1.collectionobject.text1}.equals("Medium") ? "M" :
$F{1.collectionobject.text1}.equals("Large") ? "L" :
$F{1.collectionobject.text1}.equals("Extra Large") ? "XL" :
$F{1.collectionobject.text1}