I need to show a static text field only if the price value is not null, i tried to do this:
<printWhenExpression>
<![CDATA[$F{price} != null]]>
</printWhenExpression>
But this not works, it's always returns true with Double value, in a String value it worked.
Edit: The code started to works, I will keep this because the helpfull reply.
This is not true if the $F{price} is null the expression will return false.
Maybe you do not need to check for that is null but that it is not Double.NaN
<printWhenExpression>
<![CDATA[new Boolean($F{price} != null && !$F{price}.isNaN())]]>
</printWhenExpression>
I suggest you output the value of $F{price}, to understand what it is...
NOTE: I'm using new Boolean() for compatibility reasons (jasper report v 3) this is not needed in jasper report v 5,6
Related
So in my report I want to check if the user enters a from_date and a to_date. It should also check if the entered range is lower than ten. If not I display an error with a print when expression. Currently I have:
OR(DAYS($P{P_DATE_FROM},$P{P_DATE_TO}) > 10,$P{P_DATE_FROM} == null,$P{P_DATE_TO} == null)
I also tried this:
OR(DAYS($P{P_DATE_FROM},$P{P_DATE_TO}) > 10,DAYS($P{P_DATE_FROM},$P{P_DATE_TO}) == null)
When I use the second expression (DAYS(...) == null) alone it works when I do not enter a date. When I use the first one alone it also works if the user enters a date range higher than ten.
I tried all different constelations but nothing worked. I tried to convert the date to a util.Date, because the parameters are of type sql.Date, but nothing worked. Any ideas on how to write this print when expression?
I just found the answer to my question after days of testing.
$P{P_DATE_FROM} == null || $P{P_DATE_TO} == null || DAYS($P{P_DATE_FROM},$P{P_DATE_TO}) > 10
I have a report that for a field called JobNo there are some records that have "null" as the the cell value and some that have an empty string "". there is another field called AccntNo that im also selecting by in the same selection formula.
This is what i have tried without success in the selection formula for crystal reports.
{accnt.accno} = "7015" and
{accnt.jobno} = "" or {accnt.jobno} isnull
any help is apreciated
Selection formula doesn't work as expected, sometimes.
I suppose that this will work
{accnt.accno} = "7015" and
( isnull({accnt.JobNo}) or {accnt.jobno} = "" )
First of all I put parenthesis on 'or' clause.
But, the strangest thing, is that isnull clause must be evaluated before other comparison clauses.
I am using iReport designer. I have four columns in report. Value of one column will be calculated by doing sum summation and subtraction of other columns.
My result formula looks like this :
($V{cust_amount} == null ? new BigDecimal(0) : $V{cust_amount}).subtract( ($V{airlines_amount} == null ? new BigDecimal(0) : $V{airlines_amount}).subtract(($V{indi_amount} == null ? new BigDecimal(0) : $V{indi_amount}) ) )
But the result is coming just at the next row of the expected one. I am attaching a picture also.
Here the amount -15100 should come one the first row. But every value is coming just below the right row and first row is always null.
Your ternary expression seems fine - the problem is with value assignment to the variables you are using. The values are assigned after the first row is evaluated and either never change or they are assigned the same values over and over again.
You may fix value assignment to the variables but I recommend ditching the variables and using actual fields in the expression like this $F{cust_amount} - then you will be guaranteed proper value assignment before the row is printed.
In Crystal Reports, is it possible to have a function that returns a numeric value if the if statement evaluates to true and returns NULL otherwise?
I currently have
IF ({INDICATOR} = 'Y') Then
(
{numeric value}
)
Else
(
0
);
But since 0 is a possible value of {numeric value} it doesn't make sense. Rather, I would rather have that field come up blank if the indicator isn't 'Y', but when I replace the 0 with NULL it gives me a type mismatch error.
Is there a way for me to only show the value when the indicator is 'Y'?
If you truly want a null value and not empty try the following
create a formula called NULL then save it and close without entering any data in the formula area. Then in your formula above try
If {INDICATOR} = 'Y' then {numeric value}
else tonumber({#NULL})
you can't return two different datatypes in a single if statement..If if is number then else should also be number.. instead try to split the statements and try.. something like below.
IF ({INDICATOR} = 'Y') Then
(
ToText({numeric value})
)
Else if ({INDICATOR} <> 'Y') Then
(
""
);
If {INDICATOR} = 'Y' then {numeric value}
else {Command.NULLCOL}
The setup in Database Expert is to use Add Command with sql:
select null as nullcol
from dual
Then left join to it.
A returned null value can be very powerful, so your need for a null value should not be questioned. Null values automatically display differently to stand out. Compared to 0 or "", null values work correctly with DistinctCount function. Null values also work correctly with section summaries and crosstabs, which can save you a lot of work which is the whole point of using crystal.
I am trying to suppress a sub-report.I want to check a string value either it is null or not.
If the string value is null then it will suppress.
I followed the following steps-
then I wrote a formula like
if InStr ({EmployeeHist.SpouseName},'' ) = 0 then
'N/A'
But its showing a error THE FORMULA RESULT MUST BE A BOOLEAN..
Can anyone please help??
change the formula to
ISNULL({EmployeeHist.SpouseName})
this will return true if the SpouseName is null and the subreport will be suppressed
Change the formula like this
if InStr ({EmployeeHist.SpouseName},'' ) = '' then true else false