Inclusion and exclusion of subreports (iReport-JasperReports) - jasper-reports

I need to include or exclude a subreport based on a condition. I'm using iReport to create JasperReports. I.e., if a subreport has values, I need to include that subreport, otherwise not. Can anyone please send a sample or tell me how to resolve this.

you can in the master report get data from your data source that allows you to identify if the subreport should be included, then use the 'printWhenExpression' field on the subreport element to check that data.
I use this regularly - for example the printWhenExpression field may contain:
new Boolean($F{TOTAL_STATS}.intValue() != 0)
where TOTAL_STATS is from the master report's database query. If non-zero we show a subreport detailing some data.

From my knowledge, if there aren't any data printed in the subreport, Jasper eliminates the blank space. In other words, if your subreport would normally occupy half a page, but there is no data, then the empty space is eliminated. I'm not sure this is what you mean by including or excluding the report.
Another solution would be to place the subreport in the main report, and from right-click ->properties -> Subreport tab, you select the "Subreport condition" tab and write your condition there. If the condition is true, the content of the subreport will be printed, otherwise it won't be printed.

Jamie Love's answer about "printWhenExpression" is on target.
if there aren't any data printed in the subreport, Jasper eliminates the blank space
Actually, at least in JasperReports 3.7.0 there is a subreport property "Remove Line When Blank" that controls that behavior. By default - at least when I use iReport - that parameter is off.
WEG

Related

Crystal Reports: How can a not on-demand subreport be displayed as a link in the main report

I am struggling to fix a subreport where data is obtained at the point when the main report is generated and the subreport to be displayed as a link, similar to an on demand subreport.
The issue that I have if I use a non on demand subreport is that it cannot be represented as a link, it is displayed inside the main report. As well as an on demand report is not suitable to my case because the data is retrieved when the subreport is opened.
I would appreciate any help.
Thanks in advance!
You have to take the another header for subreport and also drilldown the Header and on the Suppress formula write the formula Drilldowngrouplevel = 0 and for the Sub Report take the another detail section and on the supress formula write the formula Drilldowngrouplevel = 0.
This will definitely work, because I tried it.
Can you add a group level to the subreport and add a single line into the group header?
This will mean you will have to drill down twice to get the data though.

Hide Empty Subreport in SSRS2008 R2

I have added a subreport to my report. The aim is simply to hide the subreport if there is no data in it.
NoRows property was mentioned on this thread on Microsoft forums, but I guess it is for SSRS 2005 as the thread as quite old.
Isn't there any obvious way to hide subreport if there is no data in it? I could hide the tablix in the subreport itself, but I also need to hide the row where subreport placed. To do this I need an indication whether the subreport has data or not in the main report.
Could you give a clue to sort this out?
I had a similar problem a year ago or so. My vague recollection of this:
The default behavior as I recall was that SSRS won't show the subreport if the datasets in the subreport return no rows. This accomplishes half of what you want, but doesn't let the parent report know whether to hide the subreport area or not. IIRC, the NoRows property only controls what will be shown in this case, but it's not easily checked at run-time to change other properties.
My final solution was to create a stripped down query in the parent report that would indicate whether or not the sub report would have any rows. I used this to control row and subreport visibility.
I suspect there's a more elegant answer...
I placed the subreport in a row of its own. Then I edited the rdl file in a text editor and set the row height to 0 (The designer will not let you do this).
With the row height at 0, the row is practically hidden, until the subreport gets data, at which point, the subreport determines the row height, and it all looks normal again.
An alternative to editing the rdl may be to set the height of the row in code, I haven't looked into that though.
I ran into this issue and none of the answers worked for me. In my case I was converting a Crystal Report to an SSRS report and was using a sub-report that could occur for every group. This was fairly simple in Crystal Reports because you could suppress empty sections with a checkbox.
What worked for me in SSRS and was very clean was to add a subquery/CTE to my main report query that got a count of the number of rows that would be present in the sub-report data. For example:
SELECT CommonCriteria, Count(*) [RowCount]
FROM TableUsedInSubReport
GROUP BY CommonCriteria
Then just join this subquery/CTE to your main query on the common criteria. Once you have this it is very simple as you just right click on the far left of the row in the tablix and select Row Visbility. Then you use an expression such as...
=IIF(Sum(Fields!RowCount.Value) > 0, false, true)
That way if there are any rows to display in the sub report it will display them and if there are no rows in the sub report it will hide it and not leave white space.
i ended up using rectangle underneath the subreport - that way if subreport returns nothing, rectangle underneath it will control appearance of the cell - in my case I needed to grey out the cell if subreport returns nothing.
This thread gave me an idea How to supress empty subreports in SSRS 2008 but I did not even have to use expressions because by default SSRS won't render subreport if it returns nothing.
The more easy solution is:
Sanjay Kumar Rajarao responded on 16 Oct 2013 12:15 AM Access sub report properties - visibility - show based on expression. Enter this
code:
=IIF(RowNumber(Nothing)>0,False,True)
https://community.dynamics.com/gp/f/32/t/114129
AnarchistGeek
Hello,
I had just run into this issue myself. The ugly error along the lines of "Error: Subreport could not be shown" was really annoying me.
Solution:
To solve this, I simply nested the subreport within a rectangle and used an expression on the visibility for that rectangle like so.
ex.
=IIF(Fields!Field1.Value IS NOTHING,true,false)
(Field1 in my case was a returned data column from the parent report.)
Make your changes accordingly :)

How to suppress on-demand subreport in crystal reports?

In my report there is an on demand subreport. The subreport is sometimes empty and in these cases i want it to be suppressed (i.e. the caption should not be visible)
Is this possible?
I tried using the checkbox under subreport -> "suppress empty subreport". it doesnt work however.
Thanks
"Suppress empty subreport" will have no effect on an on-demand subreport - these are only run on demand, and until they have been run it is impossible to tell whether or not they will be empty.
If there is enough information in the main report to be able to tell whether the subreport will be empty - for example, if the subreport is a transaction breakdown and the main report includes the total transaction value, so that a total transaction value of 0 indicates that there will be no data in the subreport - then you can select Format Subreport in the main report section and conditionally suppress the subreport in the Common tab of the Format Editor dialog.

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.

Suppress Crystal Reports section if there are no rows in a datatable

I have a section in a Crystal Report that I want to suppress. I need to suppress it if there are 0 rows in a particular table in the dataset I am using. How would I do this? The Record Number special field provided appears to be an internal count of records in the report, and does not relate to the rows in the underlying data table.
I am creating the report from C#, but I cannot suppress the section from the code (it doesn't fit the project structure) - I must be able to do it from the report itself. The table concerned is definitely being passed to the report in the dataset, but it contains 0 rows. There must be a way to establish this inside the report itself.....
Can anyone please point me in the right direction?
In the Crystal Reports designer, view the properties of your section and there should be an option to Suppress, which you can give it a formula to return the appropriate boolean value.
You could then use the Count() function within that formula and (I believe) you can pass the name of your dataset to the Count() function to get the number of rows in that dataset.
I did the same thing on a complex report about 3 months ago but I don't have access to the report any more having changed jobs so I'm sorry I cannot be more specific, but hoepfully this gives you a starting point.
Just had a quick Google - try this.
If the section does only contain database fields and f.e. no text fields, then you could use the setting "Suppress Blank Section" in the "Section Export" (rightclick section) for that section.
As an alternative you could use the following formula in the "Suppress" in the "Section Export" for that section:
IsNull({table.field})
"{table.field}" is one of the fields in the dataset.
Hope this helps.
Go to "Section Expert" and click "Supress (No Drill-Down)" and try adding this:
IF {"DragYourFieldHere"} = "" then true else false
Create one dummy group,check on its header for each page,add the header in the group header of the dummy group.