Adobe ColdFusion 8

Overriding report settings at run time

You can use the cfreport tag in ColdFusion to override report settings in a Report Builder report at run time. The examples use the CFR file that you created in Creating a simple report.

Overriding the report query

This example filters the data in the report based on the log-in ID of the artist. When the artist logs on, the report displays the data and pie chart for that artist. The report also includes the pie chart with data from all the artists.

The following code creates a simple log-in page in ColdFusion. The form uses artist's last name as the user ID. (The code does not include password verification):

<h3>Artist Login Form</h3>
<p>Please enter your last name and password.</p>
<cfform name="loginform" action="artSalesReport.cfm" method="post">
<table>
    <tr>
        <td>Last Name:</td>
        <td><cfinput type="text" name="username" required="yes" message="A username is
            required."></td>
    </tr>
    <tr>
        <td>Password:</td>
        <td><cfinput type="password" name="password" required="yes" message="A password is
            required."></td>
    </tr>
</table>
    <br />
    <cfinput type="submit" name="submit" value="Submit">
</cfform>

On the processing page, add a query similar to the one you created in the Report Builder report. The ColdFusion query must contain at least all of the columns included in the Report Builder query; however, the ColdFusion query can contain additional data.

The query in the following example selects all of the data from the ART and ARTISTS tables based on the artist's last name. The cfreport tag uses the pathname of the CFR file as the report template.

<cfquery name="artsales" datasource="cfartgallery">
SELECT *
FROMAPP.ART, APP.ARTISTS 
WHERE APP.ART.ARTISTID = APP.ARTISTS.ARTISTID
         AND APP.ARTISTS.LASTNAME= <cfqueryparam value="#FORM.username#">
ORDER BY ARTISTS.LASTNAME
</cfquery>

<cfreport query="#artsales#" template="ArtSalesReport1.cfr" format="RTF"/>

ColdFusion displays the report for the artist in RTF format. Notice that the value of the format attribute overrides the Default Output format defined in the CFR file.

Exporting the report in HTML format

To generate a report in HTML format and display it directly in the browser, change the format attribute to HTML:

<cfreport template="ArtSalesReport1.cfr" format="HTML"/>

ColdFusion automatically generates a temporary directory where it stores all of the image files in the report (charts are saved as PNG files). The location of the temporary directory is:

C:\ColdFusion8\tmpCache\CFFileServlet\_cfreport\_report[unique_identifier]

You can specify when the temporary directory is removed from the server by using the CreateTimeSpan function as a value for the resourceTimespan attribute:

<cfreport query="#artsales#" template="ArtSalesReport1.cfr" format="HTML" resourceTimespan="#CreateTimeSpan(0,1,0,0)#"/>

You can specify the time span in days, hours, minutes, and seconds. In this example, the temporary directory is deleted after one hour. For more information, see the CFML Reference.

To export the report output to an HTML file, specify the filename attribute. The following code writes the report output to an HTML file called artSales.html:

<cfreport template="ArtSalesReport1.cfr" format="HTML" filename="artSales.html" overwrite="yes"/>

ColdFusion creates an image directory relative to the HTML output file in the format filename_files. In this example, ColdFusion automatically generates PNG files for the charts in the report and saves them to a directory called artSales_files. Also, it generates copies of all of the JPG images extracted from the cfartgallery database and stores them in the artSales_files directory. For more information, see the CFML Reference.

Overriding report styles

To override the report styles in a report, specify the style attribute of the cfreport tag. The value must contain valid CSS syntax, the pathname to a CSS file, or a variable that points to valid CSS code. The CSS style names must match the report style names defined in Report Builder.

The following code shows how to override the styles in the ArtSalesReport1.cfr report with the styles defined in the artStyles.css file:

<cfreport template="ArtSalesReport1.cfr" style="artStyles.css" format="PDF"/>

The following code shows how to apply a CSS style as a value of the style attribute:

<cfreport template="ArtSalesReport1.cfr" style='ReportTitle {defaultStyle: false; 
    font-family:"Tahoma"; color: "lime";}' format="FlashPaper">
</cfreport>

The following code shows how to create a variable called myStyle and use it as a value of the style attribute:

<cfset mystyle='DetailData { defaultStyle: true; font-family: "Tahoma"; color: ##00FFF0;}'>
<cfreport template="ArtSalesReport1.cfr" style="#mystyle#" format="HTML">
</cfreport>

For more information, see the cfreport tag in the CFML Reference.