Why crystal reports sub report does not display some fields on viewer - crystal-reports

I have crystal report with main report and sub report. Main report contains group sections.
I have linked sub report with main report using id. When I preview it on preview tab, both main and sub reports are working and displaying correct data.
But, when I preview it on the viewer with my application, main report data shows correct, but some sub report fields are not visible. I have noticed that, when I put the ID field to view in sub report, it shows a number of records. but only ID field is shown, and other fields are not visible.
I have set two record sets to main report and sub report. it seems records are returning data, but sub report does not shows them. Can anyone please point me in right direction to solve this?

Not sure how you are loading your report in the Crystal viewer, but keep in mind that if your report uses subreports, in your code when you are loading the report, you need to also set the data source for each subreport. See the following incomplete code snippet:
//SET DATASOURCE FOR EACH SUBREPORT IN REPORT
foreach (CrystalDecisions.CrystalReports.Engine.Section section in CrystalReportSource2.ReportDocument.ReportDefinition.Sections)
{
// In each section we need to loop through all the reporting objects
foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subReport = (SubreportObject)reportObject;
ReportDocument subDocument = subReport.OpenSubreport(subReport.SubreportName);
foreach (CrystalDecisions.CrystalReports.Engine.Table table in subDocument.Database.Tables)
{
// Cache the logon info block
TableLogOnInfo logOnInfo = table.LogOnInfo;
// Set the connection
logOnInfo.ConnectionInfo = crConnectionInfo;
// Apply the connection to the table!
table.ApplyLogOnInfo(logOnInfo);
}
}
}
}

Related

Page Break in SubReports in Crystal Report

Description
I have Crystal report with Sub Reports in Detail Section of Main Report.
The sub reports are dynamic (n number depends upon Data in Data source)
Each sub report contain Image (one image per sub report)
Problem
Sub reports are generating dynamically. let suppose 5 sub reports . The problem is the sub report footer is showing on last sub report.
What I want
I want to display sub report footer on all sub reports .
What I tried
checked / unchecked Keep Together option on detail section of main
report
checked / unchecked Keep Object Together on Sub Report
Page Break after 1 Record Option on Sub report Expert Section

CR2008 Suppressed SubReport's parameters are showing on main report

I am a very new user to crystal and have taken over a project that someone else has done and left.
Here is my current issue. I have a Main report that has a ton of sub reports on it. There is one sub-report that is suppressed that is causing a parameter prompt on the main report. I have looked through documentation about the links from main to sub but there is no link between these sub-report parameters and the main report. Also the sub report uses these parameters in the report itself. IE start date - end date are the parameters and are used on the sub report so I can't just remove them. How can I stop the prompt for these two parameters from the sub-report in the main report?
Thanks a Ton.
In the end I created a new report and just did not include the sub report mentioned. Thanks.

Crystal reports no data lable

I have a report containing some sub reports and in my main report i am showing the sub reports based on scan mode and status coming from query.
Now i need to show a message whenever sub reports don't have data.
I tried like this.
checked supress blank sub report and supress blank section for all reports.
1.Kept a text box in report footer of main report.
2.Took a field (Say Barcode) from sub report and passed to main report using shared variable.
3.In section expert of text box wrote like this.
not isnull(Barcode)
But it is not working.
Please suggest.
If I have understood this correctly the code below should work. Tip, avoid using NOT ISNULL. If possible just change the outcome order of your IF statement as below.
To make your formula more robust also, it's a great idea to add in the:
OR = ""
To account for any blank entries.
Final code:
IF Isnull({Barcode}) OR {Barcode} = "" THEN FALSE ELSE TRUE

dynamicjasper addConcatenatedReport in a frame

Is it possible to concatenate subReports in a frame placed in the detail band? The goal is to display these subReports and the previous defined elements in the Detail section from a Template.
If I use dynamicReportBuilder.setTemplateFile(TEMPLATE); and dynamicReportBuilder.addConcatenatedReport(subreport); to insert the subreports in the detail Report, which is loaded from the Template, the previous defined elements in the Detail setion of the report template dissapear. So I am looking for the way to conserve these elements.
Based on your comment it seems like one of two things is happening.
1) You have the sub-report defined in the Detail band of the Template file.
In this case it will not work. The Detail band in the template file should be empty. If this is the case it is more than likely just ignoring what ever you have there and doing everything else. Check out the HOW-TO Use custum jrxml templates for more information.
2) dynamicReportBuilder.addConcatenatedReport(subreport); does not do what you think it does.
This method appends a second report to the end of the first report. Think of it more as a batch. It is the same thing as setting a value for JASPER_PRINT_LIST as an export Parameter when using the Jasper Reports API directly. Check out the HOW-TO Add Concatenated Reports for more information.
Dynamic Jasper is a great library, but is really only designed to work with standard tabular reports. It has support for some advanced features, including sub-reports, but it can be limiting.
From what I can find so far, it appears you can only add sub-reports to the Group Headers and Group Footers. So in your case you will probably need to add a Group to report first using GroupBuilder. Then you can add the sub-report to the Group Footer. The trick for the group is to make sure that each row will end up being its own group by picking the appropriate fields to group on.
You can look at the code examples in the HOW-TO Add labels in group header and footer to see how to build the groups.
To see how to add sub-reports to the report you can use DynamicReportBuilder.addSubreportInGroupFooter() method. For more details about this part and an example check out HOW-TO Add Subreports (fast way).
The other option you have is to not use Dynamic Jasper for this particular report, and just use jrxml files and the Jasper Report's API to do it yourself. It may or may not be easier depending on your setup.
By Ricardo Mariaca. This code is the solution, Thank to Ricardo and Dynamic Report
private void build() {
try {
JasperPdfExporterBuilder pdfExporterBuilder = export
.pdfExporter(PDF_FILE);
JasperReportBuilder jasperReportBuilderMain = report()
.columns(
col.column("Item", "item", type.stringType()),
col.column("Quantity", "quantity",
type.integerType()),
col.column("Unit price", "unitprice",
type.bigDecimalType()))
.setDataSource(createSubreportDataSource())
// .detail(cmp.subreport(createSubreport()))
.setWhenNoDataType(WhenNoDataType.ALL_SECTIONS_NO_DETAIL);
JasperReportBuilder jasperReportBuilderDisclaimer = report()
.setPageFormat(PageType.A4, PageOrientation.LANDSCAPE)
.summary(cmp.subreport(jasperReportBuilderMain))
.summaryWithPageHeaderAndFooter()
.setWhenNoDataType(WhenNoDataType.ALL_SECTIONS_NO_DETAIL)
.columnHeader(
cmp.text("first page header").setFixedHeight(50))
.columnFooter(
cmp.text(DISCLAIMER).setStretchWithOverflow(true)
.setFixedHeight(250))
.pageHeader(
Templates
.createTitleComponent("Ricardo Mariaca Approach"))
.pageFooter(Templates.footerComponent).show()
.toPdf(pdfExporterBuilder);
} catch (DRException e) {
e.printStackTrace();
}
}
private JRDataSource createSubreportDataSource() {
DRDataSource dataSource = new DRDataSource("item", "quantity",
"unitprice");
for (int i = 0; i < 180; i++) {
dataSource.add("Book", (int) (Math.random() * 10) + 1,
new BigDecimal(Math.random() * 100 + 1));
}
return dataSource;
}
}

iReport, subreport does not appear

i'm trying to add subreport to report.
I have setted connection type to "use a connection expression" and the expression is $P{REPORT_CONNECTION}.
My subreport contains a simple query and some static text, when i test it all works good, but when i test mainreport the subreport does not appear.
I have some static text in subreport, this one should be display always, isn't true? But i can't see it...
During compilation i have no errors, and subreport path seems correct becouse a message say "subreport.jrxml already compiled.".
What can i do?
Thanks.
The solution is pass HIBERNATE_SESSION as parameter from master report to subreport.
Please Right clik on sub report and clik on open sub report if your sub report gets open then your reporyt is connect with your sub report. if subreport is not open do the right connection for that.
if your subreport is work for the parameter value with seperatly and displyes the static text and detail band values it is sure that the report will come ffrom main report.
but the report displays only static text and the text is in title or page heder, then you have to go to the report property and set the output when no data then choose diplay all section data from combo. your static text will apper from main report.
When you add a sub-report in your main report, the sub report expression will refer your locally saved sub-report path. Ex: "C:\abc\xyz.jrxml".
Now you can preview your main report containing sub-report in your ireport.
Once you publish the main report in Jasper server, the Sub report gets loaded into jasper repository and its expression becomes "repo:Repositorypath.jrxml".
Once sub-report contained report is published into Jasper repository, its path will always refers to Jasper repository path and because of this reason, you will not be able to Preview the main report in Ireport.
So, execute the report in jasper server directly once you publish the main report instead of previewing or opening the subreport in Ireport.
Thanks,
Srikanth Kattam