showing comparison if in iReport - jasper-reports

I have problem with IF Expression ,
This expression shows settled and outstandings records.
value = ((java.lang.Boolean)field_paid.getValue()) == false ? "Yes" : "No";
This shows transaction number:
$F{transactionNumber}
How i can report only outstanding transactions?

Related

How to use Case statement in report?

Can anyone let me know how to write a CASE STATEMENT like in SQL but in a Jaspersoft 6 report? More precisely inside the expression editor.
For example:
CASE ProductLine
WHEN 'R' THEN 'Road'
WHEN 'M' THEN 'Mountain'
WHEN 'T' THEN 'Touring'
WHEN 'S' THEN 'Other sale items'
ELSE 'Not for sale'
END
You need to use a ternary operator like below:
$F{variable_1}.equals("R") == true ? 'Road' : "Else not for Sale"
Well you can't use case directly but having if else condition within another if else condition will give the solution.
Here's an example below where the switch-case functionality is achieved through multiple if else conditions
( $F{FIELDV}.equals("ab") ? "aaaa" :
( $F{FIELDV}.equals("bc") ? "bbbb" :
( $F{FIELDV}.equals("de") ? "cccc" : ""
)))

Subtracting 2 sub queries in SSRS as an expression

I am trying to subtract 2 sub string to get a backlog of application and i am getting stuck. Can someone help me out here. The SSRS expression i am trying to write is below. What am i doing wrong?
The query will execute but won't subtract to 2 sub strings:
=SUM(IIf(Fields!NAME.Value = "TOTAL OUTSTANDING APPLICATIONS"
, Fields!DAYS_AGO.Value
, Nothing)) - SUM(IIf(Fields!NAME.Value = "ELECTION FORM RECEIVED"
, Fields!DAYS_AGO.Value
, Nothing))
Your problem is that you are aggregating NULL values with your data which results in NULL.
As long as the rest of your logic is correct, it should work if you replace the Nothings with 0.
=SUM(IIf(Fields!NAME.Value = "TOTAL OUTSTANDING APPLICATIONS"
, Fields!DAYS_AGO.Value
, 0)) - SUM(IIf(Fields!NAME.Value = "ELECTION FORM RECEIVED"
, Fields!DAYS_AGO.Value
, 0))

Crystal case to SSRS Switch statement

How can I re-write the following Formula from Crystal Reports in SSRS
select {spAR6100b_allcompanies;1.artyp}
case 'BCS','CIG','HUM','INA','INS','MNG','PHC','SEC','SPC','TRI','UHC','WMD' : 'Primary'
case 'COI','ICO','INP','MCO','COI' : 'Secondary'
default: ''
SSRS expressions generally don't work very well for IN comparisons.
There are a few options.
Use a Switch and a set of linked Or statements:
=Switch(Fields!arTyp.Value = "BCS" or Fields!arTyp.Value = "BCS" or Fields!arTyp.Value = "HUM", "Primary"
, Fields!arTyp.Value = "COI" or Fields!arTyp.Value = "ICO", "Secondary"
, True, "")
I've only included a few of your cases and you can see it's already long - you would need to add as many values as you need.
With string matches you can streamline this a bit by checking if the field value is in a string of match values:
=Switch(InStr(",BCS,CIG,HUM,", "," & Fields!arTyp.Value & ",") > 0, "Primary"
, InStr(",COI,ICO,INP,", "," & Fields!arTyp.Value & ",") > 0, "Secondary"
, True, "")
We wrap everything in commas to prevent false positives on part matches. Again, add all the required values into the string list of match values.
Finally, you could use custom code for this comparison and move the comparison to a VB.NET type function embedded in the report.

field value can't display in null condition in jasper report

I have problem when i'm using a condition for checking null values in report. My condition is
$F{BILANGAN4}==0 ? "-" : ""
The values of field does not appear but it just appear "-".
Anyone know about this?
I'm not sure what $F{BILANGAN4}==0 ? "-" : "" will compile-down to. Have you looked at the generated .java code for your report? java.lang.Long could be null, so you want to check like this:
( ( null == $F{BILANGAN4} || $F{BILANGAN4} == 0 ) ? "-" : "" )
I usually explicitly add .longValue() to calls like that just to be explicit: I'll get a compiler failure if the type isn't correct and I know I need to adjust something and maybe re-consider the code.
Note that the above code (as a text-field value for instance) will only display "-" or nothing. If you want the value of the $F to actually display, you'll have to put it in there. I'm fairly sure this is actually what you want:
( ( null == $F{BILANGAN4} || $F{BILANGAN4} == 0 ) ? "-" : $F{BILANGAN4} )

doing comparison if else in JasperReports

I want to do a comparison such as:
if <field> == 0 then "-"
Can somebody tell me the syntax using JasperReports?
iReport (JasperReports) uses a Ternary operator. For example, consider the following logic:
IF boolean condition THEN
execute true code
ELSE
execute false code
END IF
Using a ternary operator, this becomes:
boolean condition ? execute true code : execute false code
When using a variable with the following expression:
$F{column_value}.intValue() == 42 ? "Life, Universe, Everything" : "Naught"
Then the variable's value would be "Life, Universe, Everything" if, and only if, the integer value of $F{column_value} is equal to 42.
Where things get a little obtuse is when you have to have nested conditions. For these, put the nested conditions in parenthesis and on a separate line:
condition1 ?
(condition2 ? true_code2 : false_code2) :
false_code1
So when you need to do many of them:
condition1 ?
(condition2 ?
(condition3 ? true_code3 : false_code3) :
false_code2) :
(condition4 ? true_code4 : false_code4)
example of expression in ireport:
(
$F{foo} == 0 ?
"Planned" :
$F{foo} == 1 ?
"Reserved" :
$F{foo} == 2 ?
"Canceled" :
$F{foo} == 3 ?
"Absent" :
$F{foo} == 4 ?
"Complete" :
"Unknown"
)
Use if-else condition:
if customer name is null write '-' (absent), else write customer name.
Be careful of your field data type!
<textFieldExpression class="java.lang.String">
<![CDATA[
$F{CustomerName} == null ? '-' : $F{CustomerName}
]]>
</textFieldExpression>