|By Dean Harmon, Collin Tobin||
|March 15, 2005 12:00 AM EST||
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.
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
- Report Creation Wizard
- Chart Wizard
- Subreport Wizard
- Server Setup Wizard
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
The Report Builder layout has four main areas (see Figure 1):
- Properties panel
- Parameters panel
- Text Styles panel
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)
- Group management
- Images and shapes
- Report and ColdFusion expressions
- Labels and fields
- Layout controls
- Fields and parameters
- Query Builder
- Output formats
- cfreport tag modifications
- Open the Report Builder.
- Create a new report document, selecting the As a Blank Report option.
- Save your report to the webroot of your ColdFusion server, naming it FirstReport.cfr.
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:
- 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.
- Select a data source by clicking it or by clicking the plus (+) sign next to the data source to expand the list.
- Expand the data source tree.
- To view the database schema, click the plus sign (+) next to Tables.
- To view the column definitions, click the plus sign next to a table name.
- Select an RDS server.
- Expand a data source.
- 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.
- To remove a table from the Table pane, right-click it and select Remove Table.
- (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.
- Double-click the columns for the SELECT statement.
- (Optional) Specify the sort order and selection criteria.
- Review the SELECT statement that displays in the SQL pane, and use the Table and Properties panes to make adjustments, if necessary.
- (Optional) Click Test Query.
- Click Save.
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:
- 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.
- 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."
- 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.
- 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.
- 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.
- 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.
- 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).
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:
- On the toolbar, select the Subreport tool and draw an area on the Detail Band.
- When the Subreport Wizard prompts you, choose the From an Existing Report option.
- Browse to the file called consignment-report.cfr.
- The Subreport Wizard asks you to specify the bind parameters for the main report to the subreport. For this example choose #query.ARTISTID#.
- Click Finished.
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:
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
- reporting.zip (ZIP, 36K)
This article can also be read at the Macromedia Developer Center site (www.macromedia.com/devnet/)
SYS-CON Events announced today that SoftLayer, an IBM Company, has been named “Gold Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York, New York. SoftLayer, an IBM Company, provides cloud infrastructure as a service from a growing number of data centers and network points of presence around the world. SoftLayer’s customers range from Web startups to global enterprises.
Mar. 27, 2017 02:45 PM EDT Reads: 1,936
SYS-CON Events announced today that Linux Academy, the foremost online Linux and cloud training platform and community, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Linux Academy was founded on the belief that providing high-quality, in-depth training should be available at an affordable price. Industry leaders in quality training, provided services, and student certification passes, its goal is to c...
Mar. 27, 2017 02:30 PM EDT Reads: 4,008
SYS-CON Events announced today that CA Technologies has been named “Platinum Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY, and the 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 ...
Mar. 27, 2017 02:00 PM EDT Reads: 2,037
In his session at @ThingsExpo, Eric Lachapelle, CEO of the Professional Evaluation and Certification Board (PECB), will provide an overview of various initiatives to certifiy 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 worldw...
Mar. 27, 2017 01:15 PM EDT Reads: 722
SYS-CON Events announced today that Loom Systems will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Founded in 2015, Loom Systems delivers an advanced AI solution to predict and prevent problems in the digital business. Loom stands alone in the industry as an AI analysis platform requiring no prior math knowledge from operators, leveraging the existing staff to succeed in the digital era. With offices in S...
Mar. 27, 2017 01:00 PM EDT Reads: 1,451
SYS-CON Events announced today that Interoute, owner-operator of one of Europe's largest networks and a global cloud services platform, has been named “Bronze Sponsor” of SYS-CON's 20th Cloud Expo, which will take place on June 6-8, 2017 at the Javits Center in New York, New York. Interoute is the owner-operator of one of Europe's largest networks and a global cloud services platform which encompasses 12 data centers, 14 virtual data centers and 31 colocation centers, with connections to 195 add...
Mar. 27, 2017 12:45 PM EDT Reads: 1,361
SYS-CON Events announced today that T-Mobile will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on ...
Mar. 27, 2017 11:15 AM EDT Reads: 2,368
SYS-CON Events announced today that HTBase will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. HTBase (Gartner 2016 Cool Vendor) delivers a Composable IT infrastructure solution architected for agility and increased efficiency. It turns compute, storage, and fabric into fluid pools of resources that are easily composed and re-composed to meet each application’s needs. With HTBase, companies can quickly prov...
Mar. 27, 2017 10:30 AM EDT Reads: 3,009
SYS-CON Events announced today that Infranics will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Since 2000, Infranics has developed SysMaster Suite, which is required for the stable and efficient management of ICT infrastructure. The ICT management solution developed and provided by Infranics continues to add intelligence to the ICT infrastructure through the IMC (Infra Management Cycle) based on mathemat...
Mar. 27, 2017 10:30 AM EDT Reads: 3,143
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and management into a ...
Mar. 27, 2017 09:30 AM EDT Reads: 2,111
There are 66 million network cameras capturing terabytes of data. How did factories in Japan improve physical security at the facilities and improve employee productivity? Edge Computing reduces possible kilobytes of data collected per second to only a few kilobytes of data transmitted to the public cloud every day. Data is aggregated and analyzed close to sensors so only intelligent results need to be transmitted to the cloud. Non-essential data is recycled to optimize storage.
Mar. 27, 2017 08:15 AM EDT Reads: 3,107
"I think that everyone recognizes that for IoT to really realize its full potential and value that it is about creating ecosystems and marketplaces and that no single vendor is able to support what is required," explained Esmeralda Swartz, VP, Marketing Enterprise and Cloud at Ericsson, in this SYS-CON.tv interview at @ThingsExpo, held June 7-9, 2016, at the Javits Center in New York City, NY.
Mar. 27, 2017 08:00 AM EDT Reads: 4,333
SYS-CON Events announced today that Outlyer, a monitoring service for DevOps and operations teams, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Outlyer is a monitoring service for DevOps and Operations teams running Cloud, SaaS, Microservices and IoT deployments. Designed for today's dynamic environments that need beyond cloud-scale monitoring, we make monitoring effortless so you ...
Mar. 27, 2017 02:15 AM EDT Reads: 4,296
My team embarked on building a data lake for our sales and marketing data to better understand customer journeys. This required building a hybrid data pipeline to connect our cloud CRM with the new Hadoop Data Lake. One challenge is that IT was not in a position to provide support until we proved value and marketing did not have the experience, so we embarked on the journey ourselves within the product marketing team for our line of business within Progress. In his session at @BigDataExpo, Sum...
Mar. 27, 2017 01:45 AM EDT Reads: 3,042
Keeping pace with advancements in software delivery processes and tooling is taxing even for the most proficient organizations. Point tools, platforms, open source and the increasing adoption of private and public cloud services requires strong engineering rigor - all in the face of developer demands to use the tools of choice. As Agile has settled in as a mainstream practice, now DevOps has emerged as the next wave to improve software delivery speed and output. To make DevOps work, organization...
Mar. 27, 2017 01:15 AM EDT Reads: 1,974
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm.
Mar. 27, 2017 12:45 AM EDT Reads: 2,265
What sort of WebRTC based applications can we expect to see over the next year and beyond? One way to predict development trends is to see what sorts of applications startups are building. In his session at @ThingsExpo, Arin Sime, founder of WebRTC.ventures, will discuss the current and likely future trends in WebRTC application development based on real requests for custom applications from real customers, as well as other public sources of information,
Mar. 27, 2017 12:30 AM EDT Reads: 932
China Unicom exhibit at the 19th International Cloud Expo, which took place at the Santa Clara Convention Center in Santa Clara, CA, in November 2016. China United Network Communications Group Co. Ltd ("China Unicom") was officially established in 2009 on the basis of the merger of former China Netcom and former China Unicom. China Unicom mainly operates a full range of telecommunications services including mobile broadband (GSM, WCDMA, LTE FDD, TD-LTE), fixed-line broadband, ICT, data communica...
Mar. 27, 2017 12:00 AM EDT Reads: 3,443
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, will discuss some of the security challenges of the IoT infrastructure and relate how these aspects impact Smart Living. The material will be delivered i...
Mar. 26, 2017 09:45 PM EDT Reads: 2,141
Apache Hadoop is emerging as a distributed platform for handling large and fast incoming streams of data. Predictive maintenance, supply chain optimization, and Internet-of-Things analysis are examples where Hadoop provides the scalable storage, processing, and analytics platform to gain meaningful insights from granular data that is typically only valuable from a large-scale, aggregate view. One architecture useful for capturing and analyzing streaming data is the Lambda Architecture, represent...
Mar. 26, 2017 08:30 PM EDT Reads: 6,261