Subreports dependancy - jasper-reports

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.

Related

Start JasperReport subreport on new page, but not when launched as main report

I have a JasperReport named 'Receipt' that can be launched as a:
subreport in a Summary band, to display any receipts
main report, to display a particular receipt
How can I start a new page before any receipts, when it is used as a subreport, but suppress the new page if there are no receipts?
Setting isTitleNewPage="true" works when it is used in the subreport case, but causes the Detail band to be displayed on the second page when it is used as a main report.
Using a Break prior to the subreport means a redundant page is used if there are no receipts.
I solved it by:
Adding a Boolean isSubReport parameter to the report
in the Detail band, adding a Break, with a Print When Expression set to:
$V{PAGE_NUMBER} == 1 && $P{isSubReport}
In the parent report, passing the parameter isSubReport with value TRUE()
Feels like there should be a cleaner solution, but it seems to work.

Issue with passing field variable to subreport from master report

I am trying to do a simple expression in iReport, but whatever I try seems hasn't given me which I expected. It seems like such a simple thing to do, but I couldn't understand what's happening with my code.
All I'm trying to do is show a subreport when the value of an string field is a simple word like "VALUE". I am using the Print When Expression for the subreport control, however I'm not able to the see or reproduce this text with this expression. For me seems that I'm not passing well the parameters I wan't to use to do the print when expression in the subreport from the master report.
Is a disclaimer, so in master report I have a simple subreport, with the same conection from master and one parameter called Entity = "_id.Entity" (we use mongodb to get the fields for the report with a $group) and in the subreport part I have 2 text fields, the first one have the print when expression when P{Entity}.equals("VALUE"), the second one don't have any condition so this works perfectly, but the textfield with the condition doesn't work.
Any help would be appreciated. Thanks.

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.

How to pass the parameter from one subreport to another subreport

I am newbie and I'm designing my report using iReport 4.5.
I have a main report (MainReport) and three subreports (Sub1, Sub2, Sub3)
In Sub1 I have three summary variables say presentPayable, presentPayment, balance
In Sub2 I have one summary variable say totalCost
I need to use the summary variables of Sub1, Sub2 in my Sub3.
How can I do this? Is this possible to pass the variables from one subreport to another?
Otherwise please provide me any alternate to do this.
To pass a value from a subreport to its parent, the parent must first have a variable to receive the value. In your case the main report should have 4 variables, one each for presentPayable, presentPayment, balance, and totalCost.
Next you need to add a returnValue element to the subreport element in the main report. This element maps a variable in the subreport to a variable in this report using the attributes subreportVariable and toVariable.
To do this in iReport, click on your subreport element in the main report. In the properties list, click on Return Values. A dialog should appear. Click on the Add button. Type the name of the subreport variable and select the variable in this report that you would like it to be transferred to. You should leave the calculation type as "Nothing", which will instruct jasper to simply overwrite the variable with the new value. Click Ok to add this, then repeat for the other variables/subreports.
Now when you run the report, each time the subreport has completed processing, the current value of the variable in the subreport is passed back to the specified variable in the main report.
To use that value in another subreport, you need to pass the variable from the main report to the other subreport as a parameter. This has two parts: Adding a subreportParameter to the subreport element in the parent report, and adding a parameter to the subreport itself.
In iReport, click on your subreport element in the main report. In the properties list, click on Parameters. In the dialog that appears, click the Add button. Give the parameter a name (e.g. presentPayable) and input a value expression that references the variable in your main report (e.g. $V{presentPayable}). Repeat this for each of the variables that you want to pass in.
Next, open your subreport. In the report inspector, right-click on Parameters. Select Add Parameter, then rename the new parameter to match the name you entered in the previous step.
In the subreport, you should now be able to reference these values like any other parameter (e.g. $P{presentPayable}).

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.