vk01 Posted October 24, 2007 Share Posted October 24, 2007 Hi, some of the fields are returned with "null" values, is there a way to replace these? I searched the documentation for "replace" function but did not find one. Thank you. Link to comment Share on other sites More sharing options...
svenn Posted October 24, 2007 Share Posted October 24, 2007 One of the properties on a text field is "Blank when null". If you check it off your field will be blank and not contain "null". It might be a better option than replacement logic. If you're set on a dash you could use a conditional expression in the field. ( <condition> ? exp1 : exp2 ) ($F{yourValue} != null ? $F{yourValue}, "-") Link to comment Share on other sites More sharing options...
vk01 Posted October 29, 2007 Author Share Posted October 29, 2007 Thanks - this worked perfectly. But incase of a BigDecimal, how would we try to compare? It comes back with an error message? Thank you. Link to comment Share on other sites More sharing options...
svenn Posted October 30, 2007 Share Posted October 30, 2007 I've never used a BigDecimal but having looked at the Java API it looks like you would use compareTo(BigDecimal val) Link to comment Share on other sites More sharing options...
kdegraaf Posted March 4, 2008 Share Posted March 4, 2008 Hi, I'm also trying to replace null. This is what I have as Text field expression:($V{SUM_RECEIPT_AMOUNT_STAT_CURRENCY_1} != null ? $V{SUM_RECEIPT_AMOUNT_STAT_CURRENCY_1}, "-") It gives an error:Parse error at line 1,column 89. Encountered: , What do I do wrong? Link to comment Share on other sites More sharing options...
svenn Posted March 5, 2008 Share Posted March 5, 2008 kdegraaf, what class is your text field set to (ie String, Int, Double etc)? Link to comment Share on other sites More sharing options...
Pedja Posted March 5, 2008 Share Posted March 5, 2008 Put ":" instead of "," in your expression, and then check the field type. This will work for string, for some other type you have to put that type instead of "-", or leave the field as String and setting the expression as ($V{SUM_RECEIPT_AMOUNT_STAT_CURRENCY_1} != null ? $V{SUM_RECEIPT_AMOUNT_STAT_CURRENCY_1}.toString() : "-") Link to comment Share on other sites More sharing options...
kdegraaf Posted March 6, 2008 Share Posted March 6, 2008 Hi, it is a BigDecimal, This code works for me: Code:($V{SUM_RECEIPT_AMOUNT_STAT_CURRENCY_1} != null ? $V{SUM_RECEIPT_AMOUNT_STAT_CURRENCY_1}: new BigDecimal("0.0"«»)) Link to comment Share on other sites More sharing options...
soraimar Posted July 30, 2021 Share Posted July 30, 2021 ($F{value1}!=null?$F{value1}:0)jrxml variable declaration example<variable name="varWithTernary" class="java.lang.Double" calculation="Sum"> <variableExpression><![CDATA[($F{value1}!=null?$F{value1}:0)-($F{value2}!=null?$F{value2}:0)]]></variableExpression></variable> https://stackoverflow.com/questions/37674266/how-do-i-replace-a-null-value-with-0/37675092#37675092 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