Using Template Field Objects

Table of contents:

During the process of designing a report template, you might need to provide some specific formatting for a field not based on its position in the report, but instead based on the type of field it is. For example, a company might require that all date/time fields be displayed in military time regardless of operating system defaults. For example, "6:02 p.m. on March 31, 2004" would have to look like "3/31/04 18:02". Another requirement could be a space as the thousand separator for all numbers (instead of the usual comma).

These requirements could easily be corporate or industry standard requirements, such as the ISO 9000 standard. At the time the template is created, it's unknown where these fields will be located in the report or how many of them there will be. You would have to find another way of handling special formatting requirements. Template Field Objects help in this endeavor.

When designing a report specifically as a template, Template Field Objects take the place of regular database fields in a report. They can be placed anywhere that a database field would normally be placed.

These fields are a special type of formula field that contain no data but allow formats to be applied to them as if they were of any data type. Template Field Objects have a special dialog associated with them that exposes all the Formatting tabs of the Format Editor regardless of type. This provides a one-stop shop for all of your formatting needs regardless of the data type for a given position of a field in a report.

The best way to explain this is by actually performing it, so let's implement the examples given previously in this section:

  • Military Time: "6:02 p.m. on March 31, 2004" to appear as "3/31/04 18:02"
  • Thousand Separator as a space: 1,000 to appear as 1 000

Starting with a new report, follow these steps:

  1. Create a new report. After opening Crystal Reports, click the New button. Then within the Crystal Reports Gallery dialog, choose As a Blank Report and click OK.
     
  2. Skip the data source step. Because this report is going to be a template, there is no need to have a data source associated with it. Click the Cancel button in the Database Expert to close this dialog.
     
  3. Insert a Template Field object. To insert the first Template Field object, select Template Field Object from the Insert menu. Place the resulting field into the left-most area of the Details section (see Figure 14.4).
     

    Figure 14.4. The Design tab with the first template object added to the report.

    graphics/14fig04.jpg  
  4. Add five more template objects. Repeat the previous step five more times and place each new field to the right of the last one. Once completed, the Design tab will look like Figure 14.5.
     

    Figure 14.5. The Design tab with six template objects added to the report.

    graphics/14fig05.jpg  
  5. Select all template objects to format. To select all template objects, hold down the Ctrl key while single-clicking on each template object in the Details section. After all six objects are selected, right-click on the last object you chose and select Format Template Fields from the pop-up menu.
     
  6. Format Date/Time to military time (3/31/04 18:02). After the Format Editor appears, select the Date and Time tab. Choose the third option in the Style list box that represents date/time as 3/1/99 13:23 because this is the option required, as shown in Figure 14.6.
     

    Figure 14.6. The Date and Time tab of the Format Editor with Military Date/Time selected.

    graphics/14fig06.jpg

     
  7. Format Number with a space as the thousand separator (1 000) as shown in Figure 14.7. Now select the Number tab in the Format Editor dialog box. Because this style does not appear in the Style list box, select Customize. In the Custom Style dialog box, change the Symbol to ,. Click OK to return to the Format Editor. Click OK again to return to the Design tab with the changes applied.
     

    Figure 14.7. The Custom Style dialog box with the space set as the Thousand Separator symbol.

    graphics/14fig07.jpg

     
  8. Give the template a name and a preview picture. When the report appears in the Template Expert, it will have a name associated with it. The name is saved as the Report Title. To change the Report Title, select File, Summary Info. Input the name Military Time & Thousands in to the Title property field and select the Save Preview Picture check box as shown in Figure 14.8. Select OK to continue.
     

    Figure 14.8. The Report Title set to describe the Template report.

    graphics/14fig08.gif

     
  9. Save the report to the template folder. Choose File, Save As to save the report. Call the report TemplateObjects.RPT and place it in the Template folder. The Template folder is usually found at C:Program FilesCrystal DecisionsCrystal Reports 10Templates. When it is saved, close the report.
     
  10. Open the report from the previous example. Notice that all the date fields and numbers are in the standard format, as shown in Figure 14.9.
     

    Figure 14.9. The Preview tab showing how the report looked when the original report was created.

    graphics/14fig09.jpg  
  11. Select the template. To select the template that was saved earlier, select Report, Template Expert. Select Military Time & Thousands from the Available Templates list, as shown in Figure 14.10.
     

    Figure 14.10. The Template Expert dialog box with a template selected.

    graphics/14fig10.jpg

     
  12. To apply the template, simply click the OK button. The report will appear as shown in Figure 14.11. You will notice that the report appears to close. Do not be alarmed because this is standard behavior. Crystal Reports saves a temporary file with the old look of the report and then applies the template during the new open command.
     

    Figure 14.11. The Preview tab showing how the report looked after the template was applied.

    graphics/14fig11.jpg  

    TIP

    Undoing a template is always an option. If for some reason you do not like the look that the applied template has given to your report, just return to the Template Expert and choose the Undo command at the bottom of the dialog box. Selecting this option and then clicking OK lets Crystal Reports revert to the original report before the template was applied.

    Crystal Reports accomplishes this by opening up the temporary backup .rpt that it saved before applying the template file.

  13. Save the report. Choose File, Save As, call the report templateapplied.rpt, and click OK.
     

Notice that there was no need to know where the date and numeric fields were located in the report because the Template Field Objects were all formatted to handle the different requirements for the different fields. Using Template Field Objects along with the other template tips mentioned in the chapter will make report design quick and easy.

Preview Pictures

During the previous exercise, you might have noticed that the intended template did not show a preview picture on the right of the dialog window. This can be caused by one of two situations. The Save Preview Picture option in the Document Properties dialog box was not selected. If that option had been checked and the thumbnail still did not appear, it is because the template report was not saved with a Preview.

In the example that you just completed, the template report was not previewed before the report was saved.

Preview Pictures, or thumbnails as they are commonly called, are just thatpictures of the Preview of the report. If a report has not been previewed, it will not have the thumbnail to save.

Another key point to notice on Preview Pictures is that if changes are made in the design of the template and then a save is done, the changes will not be reflected in the thumbnail because the Preview tab was not updated with the changes.

Preview Pictures are very useful in the Template Expert because these images provide you with a visualization of what the template does to the existing report. To save them as a default with all reports, select the Save Preview Picture option in File, Options under the Reporting tab.

Preview Pictures are also important to have if the reports will be delivered through Crystal Enterprise because the Web Desktop application uses the thumbnails as a way to show reports in the front-end.


Part I. Crystal Reports Design

Creating and Designing Basic Reports

Selecting and Grouping Data

Filtering, Sorting, and Summarizing Data

Understanding and Implementing Formulas

Implementing Parameters for Dynamic Reporting

Part II. Formatting Crystal Reports

Fundamentals of Report Formatting

Working with Report Sections

Visualizing Your Data with Charts and Maps

Custom Formatting Techniques

Part III. Advanced Crystal Reports Design

Using Cross-Tabs for Summarized Reporting

Using Record Selections and Alerts for Interactive Reporting

Using Subreports and Multi-Pass Reporting

Using Formulas and Custom Functions

Designing Effective Report Templates

Additional Data Sources for Crystal Reports

Multidimensional Reporting Against OLAP Data with Crystal Reports

Part IV. Enterprise Report Design Analytic, Web-based, and Excel Report Design

Introduction to Crystal Repository

Crystal Reports Semantic Layer Business Views

Creating Crystal Analysis Reports

Advanced Crystal Analysis Report Design

Ad-Hoc Application and Excel Plug-in for Ad-Hoc and Analytic Reporting

Part V. Web Report Distribution Using Crystal Enterprise

Introduction to Crystal Enterprise

Using Crystal Enterprise with Web Desktop

Crystal Enterprise Architecture

Planning Considerations When Deploying Crystal Enterprise

Deploying Crystal Enterprise in a Complex Network Environment

Administering and Configuring Crystal Enterprise

Part VI. Customized Report Distribution Using Crystal Reports Components

Java Reporting Components

Crystal Reports .NET Components

COM Reporting Components

Part VII. Customized Report Distribution Using Crystal Enterprise Embedded Edition

Introduction to Crystal Enterprise Embedded Edition

Crystal Enterprise Viewing Reports

Crystal Enterprise Embedded Report Modification and Creation

Part VIII. Customized Report Distribution Using Crystal Enterprise Professional

Introduction to the Crystal Enterprise Professional Object Model

Creating Enterprise Reports Applications with Crystal Enterprise Part I

Creating Enterprise Reporting Applications with Crystal Enterprise Part II

Appendix A. Using Sql Queries In Crystal Reports

Creating Enterprise Reporting Applications with Crystal Enterprise Part II



Special Edition Using Crystal Reports 10
Special Edition Using Crystal Reports 10
ISBN: 0789731134
EAN: 2147483647
Year: 2003
Pages: 341

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