Creating and Implementing Parameters Fields

The process of using parameter fields in reports includes two distinct steps:

  1. Creation of the parameter field.

     

  2. Implementation of the parameter field into the report.

     

The remainder of this chapter uses the example mentioned earlier, the World Sales Report, to create and implement parameter fields into a report. The World Sales Report is one of the many sample reports that are provided by the Crystal Reports installation.

Reviewing Parameter Field Properties

Before you learn how to create and implement parameter fields, it is useful to understand a few common properties associated with creating parameter fields. Each of the following properties is presented within the Create/Edit Parameter Field dialog, shown in Figure 5.2:

Figure 5.2. The primary parameter field properties are presented within the Create/Edit Parameter Field dialog.

Now that you have been exposed to the primary parameter field properties, you will use these items while creating parameters for a World Sales Report, as referenced earlier in the chapter.

Creating Parameter Fields

The first step in using parameters within a report is to create the actual parameter field and define the primary properties associated with it. In the following exercise, use the Field Explorer dialog to create two new parameter fields for the World Sales Report:

To begin your exercise, open the World Sales Report within the Crystal Reports designer. This sample report should be installed in the following directory, unless you have chosen an alternative location for the sample reports during the Crystal Reports 10 installation process:

 

C:Program FilesCrystal DecisionsCrystal Reports 10SamplesEnReportsGeneral Business

After you have opened this sample report, you can begin the steps necessary to create the parameter field objects in the following way:

  1. Remove the existing report title text object. After you have opened the World Sales Report, navigate to the Design tab view, highlight and delete the text object currently used as the report's title that reads World Sales Report, located in the Report Header A section. Use your parameter field to populate the report title.

     

  2. Remove the current Top N sort order because it is not needed for your exercises. From the Report menu, select Group Sort Expert, and within the presented dialog modify the For This Group Sort: drop-down setting to display All as shown in Figure 5.3. Click OK to continue.

     

    Figure 5.3. Use the Group Sort Expert dialog to remove the Top N sort order from the report.

     
  3. Open the Field Explorer dialog by either clicking the appropriate toolbar button or using the View menu.

     

  4. Open the Create Parameter Field dialog. To do this, right-click on Parameter Fields within the Field Explorer and either select New from the pop-up menu or click on the New button at the top of the Field Explorer.

     

    TIP

    In addition to using the right-click menu to create a new parameter field, you can use the Field Explorer's toolbar commands to create, edit, rename, and delete parameter fields. The operations available on this toolbar depend on what you have selected in the Field Explorer dialog.

    You first create a manual text-entry parameter field to enable the business user to define a title to display on the report.

     

  5. Define the key properties for the parameter object. Within the Create Parameter Field, enter Title in the Name property, and provide a meaningful prompting text so that the business user understands how the entered value is used, such as, Enter a title to be used for this report.

     

  6. Select Discrete Values under the Options area and click OK to return to the Field Explorer.

     

  7. You should now see the Title parameter field listed under Parameter Fields in the Field Explorer, as shown in Figure 5.4.

     

    Figure 5.4. The Field Explorer is used to access, edit, and create parameter fields.

    You now create a second parameter field to use later in the chapter when discussing how to use parameter fields in coordination with record selections. In this way, you can filter the report data according to the selected parameter values.

     

  8. Open the Create Parameter Field dialog. To do this, highlight the Parameter Fields item and click the New toolbar button inside the Field Explorer dialog.

     

  9. Define the key properties for the parameter object. Within the Create Parameter Field dialog, enter Countries in the Name property and provide a meaningful prompting text so that the business user understands how the entered value will be used, such as, Please select one or more countries for this report.

     

  10. Select both the Allow Multiple Values and Discrete Value(s) items under the Options area, as shown in Figure 5.5.

     

    Figure 5.5. Use the Create Parameter Field dialog to create and edit parameter fields.

     

Setting Default Values for Parameter Fields

You now want to define the Countries parameter field to include all database values within the Country field of the Customer table. Map the parameter field to this database field and quickly import these values, enabling the business user of the report to select one or more country values from the available list.

When setting default parameter values, a list of default values can be read from the database or entered manually to provide the business user with a list of available values from which to choose. The Crystal Reports application enables you to define the default values list only when you are designing reports, and no direct database connection exists to populate the prompting parameter field list when the business users run the report. The following is an overview of various options available within the Set Default Values dialog to make data entry easier for the business users:

You now define the default values for your parameter fields (if necessary, refer to the list of options within the Set Default Values dialog while completing these steps):

  1. Access the Create/Edit Parameter dialog if you have closed it by highlighting the Countries parameter and clicking on the Edit toolbar button. Open the Set Default Values dialog by clicking on the Set Default Values button, as shown in Figure 5.6.

     

    Figure 5.6. The Set Default Values dialog enables you to define the default values for parameter fields.

     
  2. Choose the database table and field from which to set the defaults. Under the Select from Database area of the Set Default Values dialog, select Customer from the Browse Table list, and then select Country from the Browse Field list.

     

  3. Add the actual database values to the default value list. With all the country values listed under the Select or Enter Value to Add area on the left, use the Add All (>>) button to move all these values to the Default Values list on the right, as shown in Figure 5.6.

    Continuing the steps started above, now add descriptions to the default values that you have added to the parameter field.

     

  4. Locate and highlight the USA value in the Default Values list. Click on the Define Description button located just below the Default Values list to present the Define Description dialog.

     

  5. Add United States of America as the description for USA, as shown in Figure 5.7, and click OK to close the Define Description dialog. If you want, repeat this step for any additional default values.

     

    Figure 5.7. The Define Description dialog enables you to create user-friendly descriptions for parameter selections that can be presented to users instead of potentially cryptic database values.

    To make the default values friendlier to the business users of the report, you can sort the contents of the display prompt lists based on the Order and Order Based On option settings. Seven distinct options are available to sort the parameter field values that are reflective of the parameter value type, including both ascending and descending for the three data typesalphanumeric, numeric, and date/timeas well as No Sort. Continuing the Parameter Creation example, follow these steps:

     

  6. Sort the Country parameter field in alphabetic order. Select Alphabetical Ascending from the Order drop-down list, and choose Value from the Order Based On list, as shown in Figure 5.6.

     

    TIP

    If you select a sort type from the Order list that does not match the parameter field value type, no sorting is applied.

  7. For your purposes here, you can leave the remaining options within the Default Values dialog to their default state and click OK to return to the Create Parameter Field dialog. If desired, peruse the overview of default setting options and use these to modify the desired options for your parameter field.

     

  8. Click OK to return to the Field Explorer. You should now see the Countries parameter field listed under Parameter Fields in the Field Explorer.

     

    TIP

    There are a few considerations to keep in mind when working with parameter fields, such as

    • Any parameter field prompting text more than one line in length will automatically word wrap.
    • The creation of a pick list enables the business user to select parameter field values from drop-down boxes instead of needing to enter them manually.
    • A parameter field does not have to be placed in a report to be used in a record or group selection formula. You can create the parameter field and then enter it in your formula as you would any other field.

Implementing Parameter Fields

You have now completed the first task necessary to use parameter fields within a reportcreating the actual parameter field objects. This section, and the exercises included here, discuss how to apply these parameter fields and make use of them to provide the business user of the report with a more dynamic and interactive reporting experience.

First, implement the parameter field created earlier, called Title, to serve as the title to the report. This example demonstrates how a manual text entry field can be used to add useful commentary or descriptive information to a report. Continue working with the same report, the World Sales Report and follow these steps:

  1. Add and position the Title parameter object onto the report. Open the Field Explorer dialog and expand the Parameter Fields list. Click on the Title parameter field, drag it onto the report, and drop it into the upper-left corner of the Report Header A section, shown in Figure 5.8 in a size 20 Arial font.

     

    Figure 5.8. Drag and drop the Title parameter field into the upper-left corner of the Report Header A section.

     
  2. Preview the report. To view how this parameter is now used within the generation of the report, run the report by clicking on the Refresh toolbar button (represented by the lightning bolt icon). As shown in Figure 5.9, the report now prompts the business user to enter a value that will be used as the report's title.

     

    Figure 5.9. Parameter fields offer a means to add additional interactivity for the business users within the report.

     

NOTE

If you have already run the report at least once and then select to refresh the report, you will also see the Refresh Report Data dialog that asks you to select from the following two options:

To enter or select new values for any existing parameter fields, you need to select the second optionPrompt for New Parameter Values.

Категории