Running Your Reports


Once reports (.cfr files) have been created they must be deployed to the ColdFusion server (just like .cfm and .cfc files). Once deployed, there are two ways to generate reports, direct invocation, and via the <cfreport> tag. The latter is what developers will typically use as it provides far greater control over the report and report data.

Direct Report Invocation

To run your report, simply invoke the full URL to it from within your browser. The report will be displayed, exactly as it was when previewed in the ColdFusion Report Builder. The SQL used will be the default SQL (see the note and tip in Creating A Report above), and the output format will be the default format specified in the report properties.

NOTE

By default, the default output format is FlashPaper.


TIP

Direct .cfr invocation may be disabled in the report properties.


Invoking Reports From Within ColdFusion Code

Being able to run reports in browsers is useful, but other reporting tools can do that too. What makes ColdFusion reports unique is their ability to be altered at runtime. Here is an example:

 <!--- Get data ---> <cfquery datasource="myDsn"          name="users"> SELECT NameLast, NameFirst, Phone, EMail FROM users ORDER BY NameLast, NameFirst </cfquery> <!--- Generate report ---> <cfreport template="userList.cfr"           query="users"           format="PDF" /> 

<cfquery> was covered in Chapter 7, "Using Databases."


A <cfquery> tag is used to create a database query, and then passes that query to the <cfreport> tag overriding the query within the report. Of course, queries can be constructed dynamically, allowing for report data to be changes at runtime based on user access, prior data entry, and more.

NOTE

Any ColdFusion query objects can be passed to <cfreport>, including those returned by stored-procedure invocation, those created with QueryNew(), and any queries returned by ColdFusion Component and Custom Tag invocation.


This functionality (the ability to invoke reports programmatically) is so important that the ColdFusion Report Builder can actually automatically create calling CFML code fore you. To use this feature, open a report in the ColdFusion Query Builder, and click on the Code Snippet button (the one with tags on it). You will see a screen that contains calling CFML code, either a single .cfm or a .cfc and .cfm.. You can select the code style using the radio buttons at the bottom of the page, and then click Save to save the generated ColdFusion code read for you to use (and modify, if needed).



Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net