ColdFusion allows tremendous flexibility in the runtime customization of Crystal Reports, including the ability to dynamically set the selection formula, sort order, target data source, and any custom formula within a report. The parameters you set in the CFREPORT tag take precedence over those in the report file.
Let's start with a simple example not based on any dynamic inputs:
<CFREPORT REPORT="d:\reports\myreport.rpt">
</CFREPORT>
In most cases, reports that you run will be based on criteria specified by the user or an application. The CFREPORT tag allows the specification of this criteria in a manner similar to the way the CFQUERY tag allows the specification of dynamic SQL statements.
The next example uses a function to determine the application page path. The report displays only those records that match ZIP code and last name criteria entered into an HTML form. The curly brackets enclosing the value names are required Crystal Reports syntax.
<CFREPORT REPORT="#GetDirectoryFromPath
(Application PagePath)#myreport.rpt"
{ZipCode}="#Form.ZipCode#" AND
{LastName} LIKE "#Form.LastName#*"
</CFREPORT>
You can use the body of the CFREPORT tag to provide a custom report selection formula using Crystal Reports selection language. The following example illustrates all the tag's attributes. Note the use of the named formula "@Title" to specify the report name from form input.
<CFREPORT REPORT="#GetDirectoryFromPath
(CF_application page_path)#myreport.rpt"
DATASOURCE="CustomerReports
USERNAME="TSEliot"
PASSWORD="#Form.password#"
FORMULA="#Form.ReportTitle#">
ORDERBY="ZipCode">
{ZipCode} = "#Form.ZipCode#" AND
{LastName} LIKE "#Form.LastName#*" AND
{FirstName} LIKE "#Form.FirstName#*"
</CFREPORT>
As with CFOUTPUT, conditional processing of data using CFIF, CFELSEIF, and CFELSE provides added flexibility to your output.
|