How to pass variable's value from subreport to main report and show/hide detail band on the basis of that value in iReportDesigner Jasper Reports? - jasper-reports

I am storing Value of one field in a variable in subreport. This variable I am returning to Main report. On the basis of this value I want to show/hide detail band 2. But I am not able to implement this as the value returned by the subreport is always Null which is a shock to me as when I am displaying the same value in subreport itself it is giving me 2 (integer). Please help me out with this.

For the First part of your question
The value returned by the subreport is always Null
In your Main report please cross check the following things.
You return variables from your sub report as in specified in here.
If the subreport and the text field in which you're using the returned value are placed on the same band, you need to set evaluationTime="Band" for the text field.
For the later part of your question,
I want to show/hide detail band 2
Using the report inspector, select detail band 2.
Access the properties of the band, using the properties tab.
You can find the property PrintWhenExpression.
Edit its value to hide/display detail band 2.
The second part of the answer works on the following logic
PrintWhenExpression will be evaluated at the start of the band rendering process, before starting to render the elements.
So, if the sub-report too is in the same band, detail band 2 in your case, this method would not hold good.

Related

I need subreport just for getting some value (return value). Is it possible to hide subreport but stay it runnable?

I have a report with a sub-report. The sub-report is in the details band. And I'm getting some return values from that sub-report. I want to hide the sub-report from the details band when the report is generating (even though sub-report is empty or not). But I want to receive the return value even if the report is hidden. Is there any way to achieve this?
I have tried new Boolean(false) in Print When Expression of the sub-report. But then the main report can't receive sub report's return value.
I'm using iReport 5.6.0
The way I achieved that,
I did set the font size of the subreport elements to "0" and the band heights to "0"
So the subreport doesn't need much space so report page size can be decreased too.

The subreport repeats itself in Detail band

I am new to JasperReports, basically I want to put a subreport in a mainreport
The problem is that I put the sub report in the Detail band, so when I query a database that has multiple data the subreport will always repeat itself multiple times when I output the report to a pdf. I want a report that does not repeat itself regardless of how many data I have in the database that i connect with
I have searched the Internet and the solutions is to add
new Boolean($V{REPORT_COUNT}.intValue()==1)
in the print when expression attribute of the subreport, that does solve a part of my problem due to the fact that now my subreport only prints once but it still leaves some blank pages after my subreport is displayed
So I assume it is still repeating itself but just doesn't print the data because of the expression that I added , people say that the nature of the detail band is supposed to work that way and that I shouldn't put the subreport in the detail band, but if I put it in some other band I get this error:
Error filling print... Subreport overflowed on a band that does not support overflow.
The error above will happen if I have a lot of data to the extent that it may take up more than a page.
How do remove those blank pages? If I am ask to not put it in a detail band then what should I do? or what solution are there?
The Detail band will be generated as many times as the number of records you have in your main dataSet(populated by the top-level query).
If you want to keep the subreport in the Detail band, which is normal by the way, you can do one of these things:
either have a dummy query that returns only one record, so that the Detail band generates only once. Then, pass the report connection to your subreport. You may have done that already. This way you can run your query independently of the main report.
or leave the report as-is and add your printWhen expression ($V{REPORT_COUNT}.intValue()==1) directly on the Detail band, not on the subreport. Please note that this is just an ugly hack that may affect the report performance. Your main query still returns a lot of data that you don't use so you should consider the other options.
If you can move the subreport out of the Detail band, place it in a band that allows overflow like Title or Summary band. Then:
have your main dataSet's query empty so that no Detail band gets generated
set whenNoDataType="AllSectionsNoDetail" at the report level(in the <jasperReport> tag) so that all the other sections except the Detail get generated
exactly as in the first option above, pass the report connection to your subreport and work from there

JasperReports / iReport Designer: Can i show a band conditionally?

I have created a report as follow:
Multiple detail band
each detail band contains 1 table. Each table is linked to 1 dataset.
Can I hide the detail band whenever the result set of the query returns Empty set (no result found)?
how can I achieve this?
In the "Properties" of each Detail band you have an option called "Print When Expression" there you can place logic that evaluates to boolean.
When you fill it with your logic and it returns true this detail band is printed.
So, you will need to have the information if the table will be filled in advance and cannot address the dataset within.
If your datasets are too different to do this, you should overwrite the Dataset for the main report with a custom one that gathers the information and sets the fields appropriately.

How can I get a field to print at the top of every page in JasperReports?

I am using iReport 3.7.6 to create this report.
I have a report based off of an XML file. There is a 2-column master report and it has a detail band with a subreport.
I have a field called "Name" in the subreport. I want it to print at the top of every page. Or even at the top of every column. I have tried virtually everything I know how to do.
"Print When Detail Overflows" doesn't work, because this setting is in the detail.
I sure hope I don't need to create a subreport for every report break I want. I'll have like 4 or 5 subreports.
Is there some way to determine when the page has changed, and then use that event in a "Print When" expression?
Here is one solution, presuming the value does not change between pages:
Write a query for a subreport that obtains only the Name value.
Change the dimensions of the subreport to be as small as necessary.
Place the subreport in the page header band of the master report.
To answer your question accurately, more details (such as pictures of what you have versus what you want) would be helpful.
you can use pageCount variable which is implicitly available in jasper reports to know whether the page has changed or not.

Iterating with the subreport parameter

I have place a subreport in my master report. I have my query like, for a application I have some 3 jobID. Based on this jobID I need to fetch the related data. I placed the jobID in the detail band and passed the same to the subreport as parameter.
Since the subreport is reporting only once in the master report, even though I have 3 jobID, it is display the first jobID data in the master report.
I need to get data for all the jobID of a application.
please see whether your sub report shows value for 3id if not then it cant appear data from three reports.
also place the subreport on the details band.
simple query with tree id returnce three row in the sub report is must. then only it will apear in the main report.
Note : if you place the report on the non repeating band. then that band only show the first comming data insted of showing 3 lines.
donot place sub report on title/pageheader/column heder with repeting value.
place only those sub report on this band which give only one value or one row