The Largest Repository of ColdFusion Knowledge in The World for More Than 12 Years

ColdFusion on Ulitzer

Subscribe to ColdFusion on Ulitzer: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get ColdFusion on Ulitzer: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


CFDJ Authors: AppDynamics Blog, Michael Kopp, Tad Anderson, Bob Gourley, Jayaram Krishnaswamy

Related Topics: ColdFusion on Ulitzer

CFDJ: Article

CFDJ Feature: Creating Subreports with the Report Builder in ColdFusion MX 7

With ColdFusion MX 7, you can use subreports to show more detailed reporting

With ColdFusion MX 7, you can use subreports to show more detailed reporting. A subreport is simply a report embedded or nested inside another report. I refer to the report that contains the subreport as the main report from this point forward. The subreport and main report are typically related by the nature of their content.

In this article on ColdFusion reporting, you'll learn a couple of techniques for linking a subreport to a main report. The focus will be placed on linking subreports using the ColdFusion Report Builder.

This article covers several key concepts used for linking subreports to main reports, including how to bind reports with parameters. I discuss two techniques on how to link subreports:

  • Linking an existing subreport to a main report
  • Creating a new subreport ad hoc and linking it to the main report
Having had the daunting task of supporting reporting applications through Java applets (and I barely survived that one!), I have come to appreciate the simplicity and ease of development that comes with the new reporting paradigm. I hope that after reading this article, you will also appreciate the power and rapid development that is now available with ColdFusion reporting in ColdFusion MX 7.

Requirements
ColdFusion MX 7.0.1
For a trial download: Trial Download To buy: To Buy

Note: If you have already installed ColdFusion MX 7, please install the ColdFusion 7.0.1 updater. Also install the ColdFusion sample applications that come with ColdFusion. If you have not installed the sample applications, run the ColdFusion installer again and select Sample Applications during the installation process.

ColdFusion Report Builder
ColdFusion Report Builder (EXE, 14.7 MB): www.macromedia.com/support/coldfusion/downloads_updates.html

Tutorials and Sample Files
http:download.macromedia.com/pub/developer/subreporting.zip

Prerequisite Knowledge
Recommended skills include a basic knowledge of ColdFusion and some reporting experience. However, this article will step through the sample subreport without assuming these skills. If you are new to ColdFusion reporting, please read "Building Reports with ColdFusion MX 7" by Collin Tobin and Dean Harmon (www.macromedia.com/devnet/coldfusion/articles/reporting.html).

ColdFusion Reporting
One common function of many companies is producing reports. There have been many software packages that offer these types of solutions, including Crystal Reports, Actuate, and Microsoft Access. Over time it has become more feasible and efficient to offer reporting through Web applications. Previously, ColdFusion offered Web reporting capabilities using the cfreport tag. With ColdFusion MX 7, however, developers have access to the new ColdFusion Report Builder to develop online reports.

The ColdFusion Report Builder tool is a separate software program included with ColdFusion MX 7 that integrates with your ColdFusion server for report development. When you use the ColdFusion Report Builder to create a report, it produces a separate file with a proprietary format, and extension of CFR. You refer to the filename in the template attribute of the cfreport tag. The cfreport tag has been available in ColdFusion for some time, but with ColdFusion MX 7 it has more functionality. You can configure the Report Builder to point to the Web root of your ColdFusion server for report previews. You can easily configure your report as FlashPaper, PDF, or an Excel spreadsheet.

The Subreport Component
Typically, the ColdFusion Report Builder is used to design reports embedded in a ColdFusion page. The ColdFusion Report Builder interface is similar to that of Macromedia Flash Professional 8. There are a variety of components available in the ColdFusion Report Builder tool, including a label and a field component, each of which has its own set of properties (see Figure 1). You can change these properties when you highlight a particular component or element of your report in the Property inspector. In this tutorial, you'll use a subreport component to link a main report to an existing subreport and link a main report to a new subreport.

You use the Subreport component to embed subreports in a main report. The next section describes how to bind the subreport to the main report using subreport parameters.

Binding Subreports to Main Reports with Parameters
Generally, you can link a subreport to a main report by passing a value from the query in the main report as a parameter to the subreport; this value filters data in the subreport query. You can link the reports through the Subreport Parameters property of the subreport component. Find this property in the Data category of the subreport properties (see Figure 2).

This property corresponds to the input parameters of the subreport. The name of this property must match the name of the input parameter of the subreport. The Subreport Parameters property is an expression usually mapped to a field of the query in the main report (see Figure 3). You can view this property by clicking the ellipsis in the lower right corner in Figure 2.

Linking a Report with an Existing Subreport
You can nest an existing report as a subreport inside another report. To do this, use the sample reports included in this tutorial named Department-Employees and Company-Departments. In this exercise, the Department-Employees report is the subreport.

This tutorial assumes that you have installed the sample applications with ColdFusion MX 7. You will be using the cfdocexamples data source, which points to the cfdocexamples database. If you have not installed the ColdFusion sample applications, run the ColdFusion installer again and select the option for installing the sample applications.

Once you have installed the sample applications, follow these steps to link the two existing reports:

  1. Copy Company-Departments.cfr report to a separate folder and rename it as Company-Departments_v1.cfr. Save a copy of the original report for the next exercise.
  2. Double-click the Company-Departments_v1.cfr report. This opens the ColdFusion Report Builder. If you have not installed the ColdFusion Report Builder, do so now.
  3. Expand the Detail band of the report to about 1.5 inches. You can do this by dragging the lower bounds of the Detail section or highlight the Detail section by clicking it and typing 1.5 as the Height property in the Property inspector.
  4. Click the Subreport component in the Toolbox (see Figure 1 again).
  5. Within the Detail band drag the cross hairs from upper left to lower right. You can resize this later as needed. The Subreport Wizard appears.
  6. Select the From an Existing Report option and click the ellipses to navigate to the Department-Employees.cfr report. Click Next.
  7. Because the sample subreport is already set up to take a parameter, the Subreport Wizard next asks you to bind the subreport parameters. For the DeptID, you can select from a pop-up list with the query's variables. Select query.Dept_ID from the pop-up list and click Next.
  8. Click Finish.
  9. Resize the Subreport component to see all the fields that the query will return. The width should be approximately 6.5 inches.
At this point, your report looks similar to Figure 4.

Save your report and preview it by pressing F12 or browse to the report. With a default ColdFusion installation, for example, it would be http://localhost:8500/subreports_example/ Company-Departments_v1.cfr.

Note: If you don't see a preview of your report when you press F12, select Edit > Preferences. Select Server Connection from the Preference Groups and modify the Server Information setting so that it points correctly to your ColdFusion server.

Creating and Linking a New Subreport to Your Report
You can also create your subreport on the fly instead of linking to an existing subreport. In this section, follow these steps to create and link to a new subreport:

  1. Copy Company-Departments.cfr report to a separate folder and rename it as Company-Departments_v2.cfr. Save a copy of the original report so you can use it for other tests. Double-click the Company-Departments_v2.cfr report. This opens the ColdFusion Report Builder. If you have not installed the ColdFusion Report Builder, do so now.
  2. Expand the Detail band of the report to about 1.5 inches. You can do this by dragging the lower bounds of the Detail section or highlight the Detail section by clicking Detail and type 1.5 as the Height property in the Property inspector.
  3. Click the Subreport component in the Toolbox (see Figure 1 again).
  4. Within the Detail band drag the cross hairs from upper left to lower right. You can resize this later as needed. The Subreport Wizard appears.
  5. Select the As a New Report option and click Next.
  6. Click the Query Builder button to create a query to retrieve your recordset. The Query Builder window appears.
  7. Select your ColdFusion server for RDS.

    Note: If you have not set up an RDS server, you will need to do so now. To do so, refer to the ColdFusion LiveDocs Documentation. Expand the available data sources for your ColdFusion server, expand the cfdocexamples data source, and click Tables to expand the table choices. Double-click the Employee table. The Employee table appears in the top portion of the Query Builder.

More Stories By Jim Bambrough

Jim Bambrough taught high school mathematics and computer programming in the Phoenix area for three years. Jim currently works as a Web application developer for Amkor Technology in Chandler, Arizona. He has worked in IT since 2000 and has been developing Web-based reports at the corporate level since 2003.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
SYS-CON Italy News Desk 01/19/06 03:10:43 PM EST

With Adobe ColdFusion MX 7, you can use subreports to show more detailed reporting. A subreport is simply a report embedded or nested inside another report. I refer to the report that contains the subreport as the main report from this point forward. The subreport and main report are typically related by the nature of their content.

SYS-CON India News Desk 01/19/06 02:44:52 PM EST

With Adobe ColdFusion MX 7, you can use subreports to show more detailed reporting. A subreport is simply a report embedded or nested inside another report. I refer to the report that contains the subreport as the main report from this point forward. The subreport and main report are typically related by the nature of their content.