pennywiser Posted May 20, 2009 Share Posted May 20, 2009 Hi! I'm trying to concatenate 2 fields in a single box. The box have the "Blank when null" property checked, the problem is that when the box receive any of the fields with data, and the second field in "null" it shows the null text instead the blank space.I though about fixing it by Java code, changing the null for a blank space like " " but I would like to know if there's a way to do it with iReport 1.2.5.Thanks!Code:$F{codigoRecomendaciones}+" - "+$F{ordenRecomendaciones} Link to comment Share on other sites More sharing options...
hangman01 Posted May 20, 2009 Share Posted May 20, 2009 You should be able to create a variable and test for either item being null there. Something like this should work:$F{codigoRecomendaciones}!=null&$F{ordenRecomendaciones}!=null?$F{codigoRecomendaciones}+" - "+$F{ordenRecomendaciones}:F{codigoRecomendaciones}==null?$F{ordenRecomendaciones}:F{codigoRecomendaciones}I have never used that version of iReport but have done this type of thing in later versions so it should work. Link to comment Share on other sites More sharing options...
svenn Posted May 20, 2009 Share Posted May 20, 2009 You don't need to put this in a variable. You can put it right into the field on your report. Link to comment Share on other sites More sharing options...
hangman01 Posted May 20, 2009 Share Posted May 20, 2009 That is a good idea svenn. Link to comment Share on other sites More sharing options...
gardnerw Posted May 26, 2010 Share Posted May 26, 2010 How would i extend this to consider 8 fields any number of which could be filled? Many Thanks Will Link to comment Share on other sites More sharing options...
slow Posted May 26, 2010 Share Posted May 26, 2010 the best way is doing it with java:($F{field_1}!=null?$F{field_1}:"")+($F{field_2}!=null?$F{field_2}:"")+...($F{field_8}!=null?$F{field_8}:"")another way is to use DB function...in Oracle try nvl:select ... nvl(field_1,' '), nvl(field_2,' '), nvl(field_3,' '), ... nvl(field_4,' '), ...from aTable_________________________________________if it works... give me KARMA points please! : ) _________________________________________listening:Placebo - Where is my mind Link to comment Share on other sites More sharing options...
gardnerw Posted May 27, 2010 Share Posted May 27, 2010 Thanks Slow, I am still having a bit of a problem, if I insert a break between each field ($F{field_1}!=null?$F{field_1}:"")+($F{field_2}!=null? ", ":$F{field_2}) so when there is more than one field it grows. IE: field 1, field 2, field 3, field 4 etc but when there is just one it reads field 1. I get "," when the field is null and have "null" appearing again. Many Thanks for your help, Link to comment Share on other sites More sharing options...
gardnerw Posted May 27, 2010 Share Posted May 27, 2010 Sorry i get it, i'm being dopey! ($F{field_1}!=null?$F{field_1}:"")+($F{field_2}!=null?", "+$F{field_2}:"")+...($F{field_8}!=null?", "+$F{field_8}:"") Thanks for your help again slow! Link to comment Share on other sites More sharing options...
slow Posted May 27, 2010 Share Posted May 27, 2010 I think you're committing something wrong with java String concatenation...try this:(($F{field_1}!=null?$F{field_1}:"")+($F{field_2}!=null?","+$F{field_2}:"")+($F{field_3}!=null?","+$F{field_3}:"")+($F{field_4}!=null?","+$F{field_4}:"")) if you want delete the first "," if it apper you can use:(($F{field_1}!=null?$F{field_1}:"")+($F{field_2}!=null?","+$F{field_2}:"")+($F{field_3}!=null?","+$F{field_3}:"")+($F{field_4}!=null?","+$F{field_4}:"")).startWith(",")?(($F{field_1}!=null?$F{field_1}:"")+($F{field_2}!=null?","+$F{field_2}:"")+($F{field_3}!=null?","+$F{field_3}:"")+($F{field_4}!=null?","+$F{field_4}:"")).substring(1):(($F{field_1}!=null?$F{field_1}:"")+($F{field_2}!=null?","+$F{field_2}:"")+($F{field_3}!=null?","+$F{field_3}:"")+($F{field_4}!=null?","+$F{field_4}:""))or you can use a variable the simplify this notation... _________________________________________if it works... give me KARMA points please! : ) _________________________________________listening:Underworld - Juanita/Kiteless [Everything, Everything] oh... :)I'm posting this and in the while you have posted a reply to... :)well :) Post Edited by slow at 05/27/2010 09:53 Link to comment Share on other sites More sharing options...
gardnerw Posted May 27, 2010 Share Posted May 27, 2010 :) Defo worth the extra karma points for taking the time and patience. Thanks Slow! Link to comment Share on other sites More sharing options...
slow Posted May 27, 2010 Share Posted May 27, 2010 double post... I'm having problems with jasperserver forum :) Post Edited by slow at 05/27/2010 10:04 Link to comment Share on other sites More sharing options...
slow Posted May 27, 2010 Share Posted May 27, 2010 using variables:define a variabletemp = (($F{field_1}!=null?$F{field_1}:"")+($F{field_2}!=null?","+$F{field_2}:"")+($F{field_3}!=null?","+$F{field_3}:"")+($F{field_4}!=null?","+$F{field_4}:"").........)then in the textfield:$V{temp}.startsWith(",")?$V{temp}.substring(1):$V{temp} thanks for karma... :) _________________________________________if it works... give me KARMA points please! : ) _________________________________________listening:Underworld - Juanita/Kiteless [Everything, Everything]Post Edited by slow at 05/27/2010 10:13 Link to comment Share on other sites More sharing options...
gardnerw Posted June 12, 2012 Share Posted June 12, 2012 Hi, I hope it is OK bringing this old post back to life! I wanting to format a report to present data prefixed with text if the field was filled in the db but not if left null. I am using the following code(($F{old_tag1}!=null?"Tag Number: "+$F{old_tag1}+". ":"")+($F{tpo}!=null?" TPO Number: "+$F{tpo}+". ":" ")+($F{height}!=null?"Height(m): "+$F{height} + ". ":"")+($F{spread}!=null?"Spread: "+$F{spread} +"m. ":"")+($F{distance_road}!=null?"Distance Nearest Structure: "+$F{distance_road} + "m. ":"")+($F{dbh}!=null?"DBH(cm): "+$F{dbh}:"")+($F{dbh_2}!=null?", "+$F{dbh_2}:"")+($F{dbh_3}!=null?", "+$F{dbh_3}:"")+($F{dbh_4}!=null?", "+$F{dbh_4}+". ":"")+($F{number_of_stems}!=null?"Number of Stems: "+$F{number_of_stems} + ". ":"")+($F{age_class_description}!=null?" Life Stage: "+$F{age_class_description}+ ". ":"")+($F{vitality_description}!=null?"Vitality: "+$F{vitality_description}+ ". ":"")+($F{park_value_description}!=null?"Physiological Condition: "+$F{stability_description}+". ":"")+($F{stability_description}!=null?"Structural Condition: "+$F{stability_description}+". ":"")+($F{longevity_description}!=null?"Useful life expectancy(years): "+$F{longevity_description}+". ":"")+($F{longevity_after_description}!=null?"Useful life expectancy after work (years): "+$F{longevity_after_description}+". ":"")+($F{note}!=null?"Surveyors Comments: "+$F{note}+". ":"")) It works great if all fields are filled but if i dont fill old_tag1 for example i get the text "Tag Number:" +", ". Any help would be gratefully recieved! 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