iReport/JasperReports Server: Subreport return value null - jasper-reports

I have the following problem with iReport / JasperReports server.
I'm using a main reports with two subreports returning a calculated price, the type of the subreport variable and the local variable is BigDecimal.
If the return value from a subreport is null (no rows found) then the assigned local variable in the main report is always null. But I want to have "0.00" because I want to calculate a sum.
The construct (return_variable == null ? new BigDecimal(0) : return_variable) doesn't help as well as to set the local variable to a default value new BigDecimal(0). I always get null instead of the wanted value "0.00" ;-(
I've tested with version 3.7.6 until 4.4. of iReport, nothing helps.
Does anybody have a hint for me? Thank you in advance.

I've had the same problem, except I tried to use the return value of the subreport as a parameter of another subreport. I succeeded in getting the result I wanted by using a scriptlet in the second subreport.
I proceeded this way :
-in subreport 2, I have my parameter p (Float), its value being the return value of subreport 1
-in subreport 2, I have a variable v (Float), initialized with p
-in my scriptlet (in the method beforeDetailEval(), I test my variable v : if it is null, I assign the value new Float("0.0")
I works ok.
The limitation with this is if you want to use the return value of your subreport directly in your main report. I tried doing that, but never succeeded.
Hope this will help someone some day.
Cecilka

Yahoo! By the Grace of GOD, I found a great answer to my own question. Posting it as it may help someone in future.
1) I changed my Simple SQL Query with a MySQL stored procedure as.
My Stored Procedure as
BEGIN
SET #p = 0;
SET #n = 0;
SET #m = '00';
SELECT x.*, y.* FROM
(select #n:=#n+1 as "ID", #m:=acc as "Account" from tbl_reports) x
right JOIN
(SELECT if(#m='00',0,#p:=#p+1) as "IDU") y
ON y.IDU = x.ID;
END
In IReport, I declared my variable as
$F{IDU}>0?$F{Amount}:0
In this way, it now shows 0.00 instead of null.

Related

Crystal Reports Formula: Help forming IIF Statement

I am working with Crystal Reports 11.5.10.1263 [CR Developer Type: Full].
I am familiar with Programming and SQL syntax in general and have worked with expressions in SSRS & MS Access but never in Crystal Reports.
Problem:
I modified the SQL in the Crystal report and it has had the desired effect - except in the last part of the report output - where the changes I made to the SQL do not have the desired effect.
The 'desired effect' is that when a field named 'FundNumber' has the values '2595', '2597' Then the field named 'Organization' should be assigned the value '41600'.
The Detail Record in the Report has the following three rows as part of its 'Formula':
+ IIf({Data.Payments} > 0, "+01W ", "-01W ")
+ Left({Data.FundNumber}+ SPACE(6),6)
+ Left({Data.Organization}+ SPACE(6),6)
I want to change the Data.Organization row to an IIF Statement that says [pseucode]:
IIf Data.FundNumber IN ["2595", "2597"] Then "41600" Else Data.Organization
I believe the Left() function is saying 'return the left 6 characters of [Data.Organization + 6 Spaces] ?? and that it has to do with the way the data is presented in the output.
I would appreciate help with creating the IIF statement for this.
I included the 'IIf({Data.Payments} ...' row in case that helps - as my google searches have turned up examples that use IF instead of IIF.
Thanks!
The syntax most of the time is the same as VB. Try
IIF({Data.FundNumber} = "2595" or {Data.FundNumber} = "2597", "41600", {Data.Organization})

Jasper report expression evaluation

I have a report that evaluates values and checks if the conditions are correct, if yes it is a success and the report returns Pass
However the equation needs to be modified
Current equation is
($F{SPECPASS}.equals($F{SPECS}) ? "Pass" : "Fail")
I want the new equation to be something like this
If SPECPASS/SPECS >=0.5, then STATUS = ‘Pass’, Otherwise STATUS = ‘Fail’
I am new to Jasper reports and the version we have is 3.6.0
Thank You
I think, we can use
(($F{SPECPASS}.doubleValue() / $F{SPECS}.doubleValue() >=0.5) ?"Pass":"Fail")

Default Value for report

I'm trying too see how JasperReports Server gets the default value set in a report. I know how to set a default value in iReport, but I'm trying to come with a way to check for that value programmatically in Java.
In particular, I'm interested in a List of Values Single Value Radio Select, I am using a Resource Descriptor to get other Report data, but this seems to elude me. Any help at all would be greatly appreciated.
To set default value in case of null, you can do this
((!$F{field_name} == null) ? '0' : $F{field_name})
To get parameter type you can do
JRParameter[] params = jasperReport.getParameters();
for(JRParameter param : params) {
param.getName();
param.getDescription();
param.getDefaultValueExpression();
param.getNestedType(); // get parameter type that can be list, string
}
For detailed reference regarding Resource Descriptor you can check, they have given complete example http://jasperserver.sourceforge.net/docs/3-5-0/JasperServer-Web-Services-Guide.pdf

Crystal Reports: Create Array or get values from a column

Say I'm working on a report, on a column called someTable.someColumn. What I need is to have all of the values in the ReportHeader. I know I cound create a subreport, pass them this column and iterate it in the details, but I would like to know if it's possible to do it without a subreport.
If I use the following, I get the right result, which in my case is 9:
COUNT(someTable.someColumn)
I also tried the following, but it doesn't work - it only takes one of the 9 values randomly.
Local NumberVar i := 0;
Local StringVar Array items := {someTable.someColumn};
Local StringVar output := "";
while (i < count(items)) do (
i := i+1;
output := output + items[i];
);
output;
Is it possible to iterate over a column in order to get the values?
You can't do this in the report header. You have to use the detail section to read each value.
The only solution which springs to mind is using a subreport. Although you wouldn't pass them this column and iterate it in the details. Because it would only pass the first value from the column. You would pass it the report parameters which it could use to obtain the column values from the database the same way your main report does.
I haven't found a way to do this in the report header, but you could put it in your report footer with the following formula:
global StringVar output;
output := output + {someTable.someColumn} + ",";
This will execute each time someTable.someColumn changes over the course of report generation, and append it to the global variable. Unfortunately, it doesn't keep all instances of it up to date - for example, if you include it in the report details somewhere, you'll be able to see the evolution of output over the course of the report. In the header, it'll only display the first value.
Note: You won't want to set output := "" in this formula, as that'll reset the value each time. It seems, though, that Crystal automatically initializes the variable for you when it's created, and I didn't run into any errors with only the above formula (i.e, I didn't need to create a second formula to initialize output). I've also included a delimeter (+ ","), to help separate each of the values, but you can easily just remove that.

Crystal reports 11 : blank field bombs the report

I'm creating a invoice crystal report for sage mas 500 AR module. In it, I'm attempting to add the tarinvoice.balance field with the following formula:
if {tarPrintInvcHdrWrk.Posted} = 1 then
ToText({tarInvoice.Balance})
I'm assuming that when the {tarPrintInvcHdrWrk.Posted} = 1 conditional statement holds FALSE, it doesn't attempt to pull the invoice field because when I remove the formula from the report, the form displays correctly without it.
When the conditional statement renders true in the report, the balance fields behaves correctly. However, with the formula renders FALSE in the CR form, the entire crystal report bombs and displays blank. Any ideas why or what I'm doing wrong?
Just tried setting everything to zero and the report still bombs. I'm starting to think its more of a query error in the report. I wish there was a way to exclude the field in the query when posted = 0.
With tarinvoice.balance removed when the posted = 0, the report works fine.
With tarinvoice.balance included and posted = 1, report works fine.
With tarinvoice.balance included and posted =0, report bombs.
I believe the conditional statement fails immediately if you encounter a NULL, so your formula needs to test IsNull({tarPrintInvcHdrWrk.Posted}) before it tests equality with "1".
You can change the way Crystal handles a null value for a value in a formula. At the top of the Formula Workshop there is a drop down box that usually says "Exceptions For Nulls".
Change this to the other option "Default Values For Nulls" and your formula should no longer bomb out. You used to be able to specify the what the default values applied were, but more recent versions of Crystal have these hard coded.
Search the help for "Null Treatment" for a table showing them.
I modified the formula to this:
if isnull({tarPrintInvcHdrWrk.Posted}) = FALSE then
if {tarPrintInvcHdrWrk.Posted} = 1 then
if isnull({tarInvoice.Balance}) = FALSE then
ToText({tarInvoice.Balance})
else
"0.00"
else
"0.0"
else
"0"
The crystal report still bombs.. Nevertheless, it does show "0" in the appropriate space.
I saw a suggestion on Exp.Exch to try putting the field into a variable before converting it to text.
e.g.
NumberVar InvoiceBalance;
If isnull({tarInvoice.Balance}) then
InvoiceBalance := 0
Else
InvoiceBalance := {tarInvoice.Balance};
If {tarPrintInvcHdrWrk.Posted} = 1 then
ToText(InvoiceBalance);
I also tried to recreate your problem, since I have see similar things before.
No luck though trying with CR 8.5 & XI R2. Perhpas it has to do with linked tables as well, since I only tried on a simple single table.
I have also seen similar behaviour when using a formula within a Running Total - they do not like nulls at all!
If you put {tarInvoice.Balance} directly on report (into details "debug" section - often needed, don't forget supress it in production :)), what values it displays or does report become empty?
Maybe you have Suppress If Blank section on your report. Try to put: Else " "
if isnull({tarPrintInvcHdrWrk.Posted}) or {tarPrintInvcHdrWrk.Posted}=0 then
" "
else
if {tarPrintInvcHdrWrk.Posted} = 1 then
ToText({tarInvoice.Balance})
else
" "
I have trouble with this kind of field when making reports to export to excel. A field with no data in will pull all columns to the right of it over to "fill the gap".