Multiple nested condition in jasper ireports - jasper-reports

I have multiple fields and i want to print all the ones which are not empty or not null in ireports.Can anyone please tell me how to do it.
I have around 20 fields and some of them would be non Empty, some would be empty and i want to print all non empty values on the reports.

In iReport select each field $F{field} which you do not want to print when null, and enter the following formula under "Print When Expression":
new Boolean($F{field} != null)
When your report renders, you should see nothing if the field happens to be null.

Related

Subreports dependancy

Is there a way to show one subreport if the other subreport doesn't have any rows (doesn't return any rows).
What have I tried:
In my first subreport I returned the number of processed rows "REPORT_COUNT" to master report variable "SUBREPORT_VAR". Variable "SUBREPORT_VAR" works as it should. I added additional text field to master report and output variable to it. I set Evaluation time of text field to Band, as without this it doesn't work correctly.
Further I set option "Print When Expression" of the second subreport to:
$V{SUBBREPORT_VAR} < 1
I use jasper studio 5.5.0 final.
If there is no row count wouldn't the result be null.
If so you you could use this in the print when expression in your second subreport:
$V{SUBBREPORT_VAR}==null
another option is to run the query in your main report and use this as the subreport expression:
IF($F{SOME_VAR_FROM_YOUR_QUERY}==null,subreport2.jasper,subreport1.jasper
This prints subreport2 when your SOME_VAR_FROM_YOUR_QUERY returns null if not it prints subreport1.

JasperReports Continued on next page Grouping

I have a jasperreport that prints debtors statements. I need to print 'Continued on the next page' in place of my existing group footer when there are more records than can fit on the first page.
I have created a second group footer which has the message and I want to print this when there is more to print, and the existing when it has finished.
Is there a way I can tell, at the end of the page, if there are more records in the group to print so I can build a "Print with Expression" expression?
With thanks
Mark
Ok this is the way I solved this.
I moved my subtotals for each client to the Page Footer and I added a text field with the words 'Continued...'.
In my group footer I placed a subreport component. I created a Boolean var called returnValue and passed it to and back from the subreport which set it false.
Using the print expression I only print the subtotal fields when returnValue is false and the 'Continue...' field when it tests null.

Crystal report conditional section suppress

I've made a crystal report which has a section with name "detail d", and would like to suppress this section if the field "stock_gift" is empty (i.e. "")
I've set the condition in the section expert using below condition:
(trim({gift.stock_gift}) = "" or isnull({gift.stock_gift}))
But the section isn't suppressed, I checked the database whether the field is an empty string and it shows it's an empty string:
Is there anything wrong with the formula that caused the section unable to suppress?
Are you sure that {gift.stock_gift} contains the empty string and NOT a null value? If it's a null then your suppression formula won't work correctly as it is; you need to either swap the order of your boolean statements like this:
isnull({gift.stock_gift}) or trim({gift.stock_gift}) = ""
Or get rid of everything except for the isnull() check. The reason for this is that if CR encounters a null value in a formula and it's not handled via isnull() as the very first thing in the formula, then that formula will produce an error exception and will not continue to be evaluated.

iReport subreport return value

I am using iReport 4.0.2 and I want to show a result in my main report. For example, in my main report we have two columns and I want to get the sum of that two columns, just like this format:
A B sum
10 5 15
Where A is one field in the main report and B is a return value of my subreport.
This works well. But, the key point is that sometimes subreport will not return any value, which is the problem. In this case, the result of sum is like this:
A B sum
10 NULL
As we see here, B is the subreport return value but it's value neither NULL nor 0 . That's why we have that problem.
I try to find how can I get the return value from subreport when the SQL returns no results. I know iReport has a property named 'When No Data', but it doesn't help.
So I want to know, whether we have another way to solve the problem in iReport or using some SQL skills.
I think that in your second example B is actually null but perhaps your text field has the 'Blank When Null' property set. I was able to reproduce your results except for the blank for B.
The real issue is that you can't add or subtract with a null value. JasperReports will just print null. You have to add some logic to provide a default value if one of the variables in the expression is null. For example
$F{MAIN_REPORT_FIELD} - ($V{SUB_RESULT} == null ? 0 : $V{SUB_RESULT})
Unfortunately, this is broken for reports that use Groovy for expressions in JasperReports 4.0.2 (Case 0005138) and will always return null.
You have a few options:
You could upgrade to JasperReports/iReport 4.1.1 which resolves this issue.
You could switch to using Java for expressions.
Depending on your report this will either be painless or it will be a chore. Any fields that don't have the correct Expression Class will have to be fixed up and you'll probably have to be more explicit in any expression that performs operations on non primitive/wrapper types.
if you are doing sum of main field and sub report field in main report then in the sum expression (main report field + (subreportfield==null ? 0 : subreportfield) .
return subreport values to main report variable.
Then do the sum of the main report field and bareport return variable.
Do the same condition as given above.

'This field name is not known' error (Crystal Reports)

Here is a strange problem I have run into.
My record select formula is as follows, I have dumbed it down for purposes of this error:
reportDocument.RecordSelectionFormula = " {#ClientName} = 'Smith' "
If I copy this exact selection statement into Crystal it previews fine, but when run from .NET I get
'This field name is not known'.
The problem is occurring at the #ClientName formula field.
#ClientName simply contains:
formula = {aw_illust.CL1LNAM}
I can also set it to just a blank string (formula = "") and it still gives
'This field name is not known.'
Here is the strange part, if I bypass the formula and put the formula text straight into .NET everything works fine.
reportDocument.RecordSelectionFormula = " {aw_illust.CL1LNAM} = 'Smith' "
That is the same record selection, except with the '#ClientName' formula replaced with '{aw_illust.CL1LNAM}'. It just happens on this one report, I have many other Crystal Reports working with formulas referenced in .NET just fine. Any ideas?
Most likely you are not using your {#ClientName} formula anywhere on report; Crystal Reports tends to ignore unused fields, formulas etc. Place {#ClientName} field somewhere in report (header or some similar section) and suppress it - this way you don't mess up report design, but CR should know about that formula afterwards.
Which syntax has the formula? If it is crystal syntax then change it to basic syntax. Or change the content of the formula to crystal syntax (without "formula =")
You could create a parameter like {?ClientName} and set that from .NET, and then put a select formula in Crystal like {#ClientName} = {?ClientName}.
Can you save the report with the selection criteria you'd like then display what the reportDocument class sees using something like:
TextBox1.text = reportDocument.RecordSelectionFormula
This would confirm that your syntax is correct.
Same happened with me when I copied existing report to be used as the new one, You can first open report in report viewer ,In my case
but the query that loading report has no selection with name DateLocal Transaction so I got this error, the resolve is to either use only those that are require (Extras has nothing to do with the error) or rename selection value in query.