Welcome!

Adobe Flex Authors: Matthew Lobas, PR.com Newswire, Shelly Palmer, Kevin Benedict

Related Topics: Adobe Flex

Adobe Flex: Article

Building Reports with ColdFusion MX 7

How to generate your first ColdFusion MX 7 report (previous ColdFusion knowledge is helpful but not necessary)

Reporting is one of the most common tasks developers have faced since the beginning of the IT revolution. In the past, Macromedia ColdFusion developers didn't have many choices for easily creating reports and integrating them with their applications. They either had to leave the comfort of using ColdFusion and use a third-party solution or write CFML to generate HTML layouts - a solution that involved writing a lot of CFML code to read data from database, slice and dice the data, and generate HTML output.

Doing that kind of work can be tedious, repetitive, and just plain boring. Even after all that hard work, the final result can be less than optimal. Because HTML has no notion of page breaks, page headers, and footers, the results seldom look very good when the browser sends a report to the printer.

In ColdFusion 7, the ColdFusion engineering team has created a reporting feature to help liberate you from such tedious tasks. Now you can spend more time developing dynamic applications and less time worrying about whether or not it will print well.

Requirements
To complete this tutorial you will need to install the software and files listed at the end of the article. Previous ColdFusion knowledge is helpful but not necessary.

Getting Familiar with the New CFREPORT Tag Syntax
The cfreport tag has undergone some slight revisions. Aside from still supporting its usual syntax that supports Crystal Reports integration, the new syntax is as follows:


<cfreport
     template = "report definition filename"
     format = "PDF or FlashPaper" or "excel"
     name = "cf variable"
     filename = "output filename"
     query = "query variable"
     overwrite = "yes" or "no"
     encryption = "128-bit" or "40-bit" or "none"
     ownerpassword = "password"
     userpassword = "password"
     permissions = "permission list"
>
     cfreportparam tags [optional]
</cfreport>

The ColdFusion MX 7 Reporting Solution
The ColdFusion reporting solution contains two parts: a report engine and a report designer.

The report engine contains the following functionality: graphing capability, columnar layouts, support of report runtime input parameters, and the ability to output in three formats (Adobe PDF, Macromedia FlashPaper, and Microsoft Excel). You can output these files directly to a browser, save them to disk, or send them through e-mail.

The report feature gives ColdFusion developers many advantages over third-party solutions:

  • It understands CFML expressions
  • It can use data sources defined in the ColdFusion Administrator
  • It has access to shared scopes
The report builder contains the following wizards to help you create reports:
  • Report Creation Wizard
  • Chart Wizard
  • Subreport Wizard
  • Server Setup Wizard
Let's discuss the report builder some more.

Introducing the ColdFusion Report Builder
The ColdFusion Report Builder is a tool you can use to create ColdFusion report files (CFR files) that the report engine will consume. The Report Builder is only available to Windows users, even though the reports themselves can run on most platforms to which ColdFusion deploys (Windows, Linux, Solaris, Mac OS X, HPUX, and AIX specifically - HPUX and AIX are only supported through pure Java deployments).

When you run the Report Builder for the first time, the Server Setup Wizard helps you configure Report Builder to work with ColdFusion Server. You can modify all of the settings in the Server Setup Wizard from the preferences screen, or you can run the wizard again.

ColdFusion reporting uses a banded-report writing paradigm. In other words, each section of the report is separated into different bands; a section, or band, is a printable region of the report. Each band has its own rules that specify when and how to print. The Report Builder lists each of these bands in the work area from the top to the bottom in the following order:

  • Report Header
  • Page Header
  • Column Header
  • Detail, Column Footer
  • Page Footer
  • Report Footer
There is also a special band called "Watermark" that prints in the background of every page. You can get more information about the different bands by using the integrated help system from the Help menu.

The Report Builder layout has four main areas (see Figure 1):

  • Workspace
  • Properties panel
  • Fields
  • Parameters panel
  • Text Styles panel
Use the Workspace in the middle of the screen to place your images, labels, or text - anything - that you want to print. When you select an object or text in the workspace, the Properties panel in the upper right displays the properties available for that object. The Fields and Parameters panel below the Properties panel displays the fields (either from your database or ones that the report calculates) and parameters that are available for your report. Last, use the Text Styles panel to set text attributes in your report quickly and easily.

Building a Sample Report
In this tutorial, you will build a sample report with the ColdFusion Report Builder to help you understand the following features of ColdFusion MX 7 reports:

  • Layout of a banded report
  • Database access
  • Text formatting (styles)
  • Text formatting (ColdFusion)
  • Subreporting
  • Group management
  • Images and shapes
  • Report and ColdFusion expressions
  • Labels and fields
  • Layout controls
  • Fields and parameters
  • Query Builder
  • Output formats
  • cfreport tag modifications
In the following section, you will create a new report that contains several elements: report header, page header, detail pages, and queries:
  1. Open the Report Builder.
  2. Create a new report document, selecting the As a Blank Report option.
  3. Save your report to the webroot of your ColdFusion server, naming it FirstReport.cfr.
By default the Report Builder shows a select number of report bands: Report Header, Column Header, Detail, Column Footer, and Report Footer. The Report Builder doesn't show the following by default: Page Header, Page Footer, Watermark, and those bands created when using the "Group Management" option (explained later).

The bands displayed represent everything that your report can contain. Some bands, like the Report Header, appear only once - in this case at the top of the very first page of the report. Other bands, most importantly the Detail band, will be iterated over a number of times, depending on your query data, grouping, and number of pages.

Building a Query for Your Report in the Query Builder
To open the Query Builder, select Report > Report Query from the menu bar, or click the Report Query button on the menu bar. The Query Builder appears. Now select a data source:

  1. Make sure that you have selected the appropriate RDS server, choosing an RDS server from the pop-up list box above the tree control. The Report Builder displays a list of data sources defined for the associated ColdFusion server.
  2. Select a data source by clicking it or by clicking the plus (+) sign next to the data source to expand the list.
  3. Expand the data source tree.
  4. To view the database schema, click the plus sign (+) next to Tables.
  5. To view the column definitions, click the plus sign next to a table name.
Build an SQL statement using the Table pane and the Properties panel:
  1. Select an RDS server.
  2. Expand a data source.
  3. Drag one or more tables from the Table pane to the Data Source pane. Alternatively, right-click a table and select Add to Work Area. You can also select a table by double-clicking it or by right-clicking on the Table pane.
  4. To remove a table from the Table pane, right-click it and select Remove Table.
  5. (Optional) If you select more than one table, you must specify the column or columns used to join them by dragging a column from one table to the related column in the second table.
  6. Double-click the columns for the SELECT statement.
As you select columns, the Query Builder creates the SELECT statement in the area in the bottom half of the pane:
  1. (Optional) Specify the sort order and selection criteria.
  2. Review the SELECT statement that displays in the SQL pane, and use the Table and Properties panes to make adjustments, if necessary.
  3. (Optional) Click Test Query.
  4. Click Save.
The Query Builder saves the SQL statement as part of the report and defines query fields for columns returned by the result set. See the ColdFusion LiveDocs on Report Builder for more information. For the example in this tutorial, the Query Builder should look like Figure 2.

The report samples use "text styles" to format elements that display fonts. A text style is similar to a font style in Microsoft Word. Instead of explicitly associating a text element with font specifications, you associate the element with a text style.

Formatting Your Report
To begin formatting your report, take a look at Report Builder toolbox. The toolbox contains everything you need to draw, type, place, and embed everything you need in the report.

Formatting the Report Header
Use the following steps to create a Report Header from the Report Builder toolbox:

  1. Click the lightning bolt button. This is the field control, which allows for the display of textual expressions to be rendered in your report. Expressions, as you'll see, can contain any and all of the following: static text, dynamic text, calculated text, and concatenated text.
  2. Use your cursor to resize the Report Header. A dialog box appears and asks you to select one of the following choices: pre-existing values in the report (such as data from the query you built in the Query Builder), or a manually entered expression. Select manually entered expression; and for the expression enter the following:

    
    "Report Format is " & param.outputFormatLabel
    

    This expression concatenates static text with a predefined report parameter -named outputFormatLabel, specified in the cfreportparam tag, embedded in the cfreport tag - which ultimately invokes our report (covered later). So as we explained earlier, anything in the Report Header appears once on the first page of your report. In this instance, it will print out something like "Report Format is FlashPaper."

  3. Because you want the text to appear in the upper left of the Report Header while the text field is selected (denoted by the handles that appear on the rectangle), click the Align to Band button in the Align palette, click the Align Left Edges button, and then the Align Top Edges button. These steps move the text to the top-left band while respecting the outermost boundaries of the band.
  4. To resize or move the band while you have selected it, click and drag the entire element, use your keyboard arrows, click and drag the element's handles, or alter the values for this element in the properties panel under "Layout" - values such as Height, Width, Left, Top, and so forth. For every new type of element you use in your report, note the related properties of that element in the Properties panel; this will help you be aware of every configurable property available to you.
  5. Supply a static text report title. In the Toolbox, click the abc button (when you place your cursor over it, "Label" appears). Draw a rectangle the width of the entire Report Header band. Notice that when you release the cursor, the Report Builder doesn't ask you to enter an expression, but to enter label text. Enter the following:

    
    Works of Art on Consignment (grouped by Artist)
    

    Notice that with any text, you can align the text box surrounding it and also align the text within the text box by selecting Properties Panel > Format > Alignment, or using the Text and Styles toolbar. Additionally, the dynamic and static fields appear differently in the report. Fields have a solid line on the text box perimeter. Labels only have bracket in its corners.

  6. You're almost done with the report header, but it has no color. Click the "Rectangle" button in the Toolbox and drag it much like a text control. Adjust the control points so that the rectangle occupies the entire width and height of the header band. While selecting the rectangle, set the background color to any color of your choice by selecting Properties Panel > Colors & Style > Background Color, or by using the Background Color paint bucket in the Text Styles panel.
  7. Notice that the rectangle in the report covers the two elements you put in the report header - this is referred to as the z-order. You've essentially stacked your rectangle on top of the other elements. Right-click your rectangle and choose Send to Back. As with most every command in the Report Builder, there are at least one or two other ways to do the same (keyboard shortcuts, panels, toolboxes, right-click menus).
You're done with the header!

Formatting the Page Header
Enter today's date in the Page Header. Conveniently, this ColdFusion report processes much like a ColdFusion page itself, and has access to all variables accessible to the page that contains the cfreport tag invoking the report (that is, unless a user browses to the report definition directly), and also has access to all ColdFusion functions.

To explore functionality available to your report, drag a text field (dynamic - remember lightning bolt) onto the Page Header and enter the following expression:

DateFormat(Now (), "d mmmm yyyy")

You've just used a widely known ColdFusion function, Now(), and formatted it with another function, DateFormat(). Notice that as you entered the expression, the Expression Builder was insightful and prompted you with code completion options. Take advantage of this feature or simply continue typing.

Formatting the Detail Band
Now onto formatting the core of the report, the Detail Band. This band prints in your report for every row of data returned from your report query (the query that you specified in your report through the cfreport tag or that you embedded in the report itself, through the Query Builder).

See if you can mimic the layout described below in your detail band, knowing what you know about fields, labels, layout, and expressions. If you're not terribly knowledgeable with CFML, don't work on this until you're more familiar with the functions below. Note that items in parentheses are instructional; do not include them in the report. Give it a try:


------ Detail Band Start ------
(Label) Artist Contact Info
(Label) Name: (Field) query.FIRSTNAME & " " & query.LASTNAME
(Label) Address: (Field) report.FormatAddress
("", query.ADDRESS, "", query.CITY, query.STATE, query.POSTALCODE)
(Label) Email: (Field) query.EMAIL
(Label) Phone: (Field) report.FormatPhone(query.PHONE, "", "")
(Label) Fax: (Field) report.FormatPhone(query.FAX, "", "")

(Label) "See all artwork by " & query.FIRSTNAME
------ Detail Band End ------

Note: To display the images in the reports you must specify the path for the image files dynamically. In this case, I have used Application.cfm to define an application-level variable called application.sImageLocation. In the report you named works-of-art-by-artist.cfr, the field element under the image label has the following expression: application.sImageLocation & "/" & query.LARGEIMAGE. Because the table stores the image filename, concatenating the path to the image helps your report dynamically find the image files.

Adding a Subreport
You have one more element to add to the Detail Band - another report! This other report serves as a subreport to the main report. Subreporting, conceptually, is much like how a ColdFusion developer would group query data, with nested cfoutput tags.

Use subreports to nest a report within another report. The data you display in a subreport is typically related to the data in the main report. You invoke a subreport by passing one or more subreport parameters from the main report to the subreport. However, the data displayed in a subreport can also be unrelated to the data in the main report. Other common ways to refer to this relationship between these reports are master/detail or parent/child:

  1. On the toolbar, select the Subreport tool and draw an area on the Detail Band.
  2. When the Subreport Wizard prompts you, choose the From an Existing Report option.
  3. Browse to the file called consignment-report.cfr.
  4. The Subreport Wizard asks you to specify the bind parameters for the main report to the subreport. For this example choose #query.ARTISTID#.
  5. Click Finished.
See documentation on subreports in the ColdFusion MX LiveDocs for more information.

Adding a Page Footer
In the Page Footer, place a Field control, entering within it the self-explanatory variable: calc.PAGE_NUMBER

The calc.PAGE_NUMBER variable is one of a few variables available to any report Other variables are:

  • calc.PAGE_NUMBER
  • calc.COLUMN_NUMBER
  • calc.REPORT_COUNT
  • calc.COLUMN_COUNT
Check out the Report Builder documentation in "Built-in Calculated Fields and Input Parameters" in ColdFusion MX 7.

LiveDocs
Browsing Your Report
The ColdFusion code needed to render this report is minimal because you've already embedded your query in the report definition. Save this ColdFusion code in your webroot (where your CFR file is located). Save it as FirstReport.cfm:


<cfreport template="FirstReport.cfr" format="flashpaper">
     <cfreportparam name="outputFormatLabel" value="flashpaper">
     <cfreportparam name="reportTemplateName" value="FirstReport">
</cfreport>

Browse to FirstReport.cfm and the FlashPaper version of your report appears. Go ahead and change the cfreport tag attribute value for format from flashpaper to pdf to excel.

Congratulations! You've generated your first ColdFusion MX 7 report. If you think that was fun, try the Report Wizard next!

Source Code and Files Necessary for This Article
ColdFusion MX 7

  • Try
  • Buy
Tutorials and sample files:
  • reporting.zip (ZIP, 36K)
Note: This ZIP file contains the sample files to build your first report. If you installed ColdFusion MX 7 without the sample applications, run the installer again and select the Sample Applications option during the installation process.

This article can also be read at the Macromedia Developer Center site (www.macromedia.com/devnet/)

More Stories By Dean Harmon

Dean Harmon has been with Macromedia since 2001. Originally he was on the Visual Tools team developing HomeSite before transitioning to ColdFusion. He enjoys creating and playing video games and spending time with his wife and three children.

More Stories By Collin Tobin

Collin Tobin joined Macromedia in 2001. He is currently a principal quality assurance engineer for ColdFusion. Previously he worked at Gtriad as a web developer.

Comments (0)

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.


@ThingsExpo Stories
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
Amazon started as an online bookseller 20 years ago. Since then, it has evolved into a technology juggernaut that has disrupted multiple markets and industries and touches many aspects of our lives. It is a relentless technology and business model innovator driving disruption throughout numerous ecosystems. Amazon’s AWS revenues alone are approaching $16B a year making it one of the largest IT companies in the world. With dominant offerings in Cloud, IoT, eCommerce, Big Data, AI, Digital Assista...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
When growing capacity and power in the data center, the architectural trade-offs between server scale-up vs. scale-out continue to be debated. Both approaches are valid: scale-out adds multiple, smaller servers running in a distributed computing model, while scale-up adds fewer, more powerful servers that are capable of running larger workloads. It’s worth noting that there are additional, unique advantages that scale-up architectures offer. One big advantage is large memory and compute capacity...
No hype cycles or predictions of zillions of things here. IoT is big. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, Associate Partner at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He discussed the evaluation of communication standards and IoT messaging protocols, data analytics considerations, edge-to-cloud tec...
"When we talk about cloud without compromise what we're talking about is that when people think about 'I need the flexibility of the cloud' - it's the ability to create applications and run them in a cloud environment that's far more flexible,” explained Matthew Finnie, CTO of Interoute, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that MobiDev, a client-oriented software development company, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business...
SYS-CON Events announced today that GrapeUp, the leading provider of rapid product development at the speed of business, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company, specialized in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market acr...
SYS-CON Events announced today that Ayehu will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara California. Ayehu provides IT Process Automation & Orchestration solutions for IT and Security professionals to identify and resolve critical incidents and enable rapid containment, eradication, and recovery from cyber security breaches. Ayehu provides customers greater control over IT infras...
We build IoT infrastructure products - when you have to integrate different devices, different systems and cloud you have to build an application to do that but we eliminate the need to build an application. Our products can integrate any device, any system, any cloud regardless of protocol," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA
With the introduction of IoT and Smart Living in every aspect of our lives, one question has become relevant: What are the security implications? To answer this, first we have to look and explore the security models of the technologies that IoT is founded upon. In his session at @ThingsExpo, Nevi Kaja, a Research Engineer at Ford Motor Company, discussed some of the security challenges of the IoT infrastructure and related how these aspects impact Smart Living. The material was delivered interac...
Artificial intelligence, machine learning, neural networks. We’re in the midst of a wave of excitement around AI such as hasn’t been seen for a few decades. But those previous periods of inflated expectations led to troughs of disappointment. Will this time be different? Most likely. Applications of AI such as predictive analytics are already decreasing costs and improving reliability of industrial machinery. Furthermore, the funding and research going into AI now comes from a wide range of com...
In his session at Cloud Expo, Alan Winters, an entertainment executive/TV producer turned serial entrepreneur, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to ma...
IoT solutions exploit operational data generated by Internet-connected smart “things” for the purpose of gaining operational insight and producing “better outcomes” (for example, create new business models, eliminate unscheduled maintenance, etc.). The explosive proliferation of IoT solutions will result in an exponential growth in the volume of IoT data, precipitating significant Information Governance issues: who owns the IoT data, what are the rights/duties of IoT solutions adopters towards t...
SYS-CON Events announced today that Enzu will exhibit at SYS-CON's 21st Int\ernational Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive advantage. By offering a suite of proven hosting and management services, Enzu wants companies to focus on the core of their ...
In his session at @ThingsExpo, Eric Lachapelle, CEO of the Professional Evaluation and Certification Board (PECB), provided an overview of various initiatives to certify the security of connected devices and future trends in ensuring public trust of IoT. Eric Lachapelle is the Chief Executive Officer of the Professional Evaluation and Certification Board (PECB), an international certification body. His role is to help companies and individuals to achieve professional, accredited and worldwide re...
SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...