In addition to some of the conditional reporting features discussed elsewhere in this chapter, Crystal Reports allows you to highlight records that meet a requirement using Report Alerts. Report Alerts enable you to set up a condition that Crystal Reports checks for every time you refresh the report (by clicking the Refresh button in the Standard toolbar, by selecting Report Refresh Report Data from the pull-down menus , or by pressing the F5 key). Report Alerts can also be used to highlight desired conditions or send an e-mail when reports are scheduled with the Crystal Enterprise web-based reporting system (covered in Part II of this book).
While you ve always been able to conditionally format report sections and objects in terms of a condition, you might not have always known which customers, sales reps, months, and so forth had triggered this condition without going through the report page by page looking for the conditionally formatted sections. Now when a report with Report Alerts defined runs, a separate dialog box will pop up if any of the conditions on the report have been met. You can then click a button on the dialog box to display a separate tab (similar to a drill-down tab) that shows only report records that meet the alert condition.
To work with Report Alerts, choose Report Alerts Create or Modify Alerts from the pull-down menus. The Create Alerts dialog box will appear, as shown in Figure 9-7. If any existing alerts have already been created in the report, they ll appear inside this dialog box. If you wish to modify any existing alert, select it in the dialog box and click the Edit button. To delete an existing alert, select it and click the Delete button. If there are no alerts in the report yet, the dialog box will be empty.
To create a new alert, click the New button. The Create Alert dialog box will appear, as shown in Figure 9-8. At minimum, you must specify the name of the Report Alert in the Name text box, and the condition that will trigger the alert by clicking the Condition button. You may optionally type a message that will appear when the alert is triggered in the Message text box, or customize the message with a string formula you create by clicking the conditional formula button. Clicking the Condition button will display the Formula Editor, where you enter a Boolean formula that determines when the alert will be triggered (see Chapter 5 for information on Boolean formulas). If you wish to temporarily disable the alert without deleting it entirely, deselect the Enabled check box.
For example, you may wish to create a simple report showing orders that were placed. If the order amount exceeds a certain level ($5,000, for example), you wish to trigger a report alert. Create the report as you usually would and then create a new Report Alert. Give the alert a name of your choosing (perhaps Order Exceeds 5,000 ), type any message you want to appear when the alert is triggered, and then click the Condition button. Enter a Boolean formula to indicate what records should trigger the alert, such as
{Orders.Order Amount} > 5000
Once you ve saved the alert, simply refresh the report. If any order amounts in the report exceed $5,000, you ll receive an alert dialog box indicating that the alert has been triggered.
To see a separate tab showing all report records with orders that exceed $5,000, just click the View Records button. A separate tab (similar to a drill-down tab, discussed in Chapters 3 and 10) will appear showing just the relevant records.
You don t have to just base Report Alerts on database fields, as in the previous example. You can also base report alerts on summaries or subtotals in group footers (although you can t base Report Alerts on WhilePrintingRecords or second pass formulas). For example, you may prefer to create a parameter field (discussed in Chapter 14) to prompt the user for a customer total threshold. You can then create a Report Alert that will be triggered if an order subtotal in a customer name group footer exceeds the value supplied by the parameter field. In this situation, the Boolean formula used to trigger the alert will look something like this:
Sum ({Orders.Order Amount}, {Customer.Customer Name}) >
{?Report Alert Threshold}
While it s helpful to see a dialog box showing that a Report Alert has been triggered, and see a separate tab of report items that triggered the alert, you may appreciate the additional power afforded to your formulas by Report Alerts as well. Three functions exist in the formula language in Crystal Reports to support alerts: IsAlertEnabled, IsAlertTriggered, and AlertMessage. Each of these new functions takes one parameter, the name of a previously created report alert:
IsAlertEnabled Returns a true or false value, depending on the state of the Enabled check box in the Create Alert dialog box (shown in Figure 9-8 earlier in the chapter). If the alert is enabled, then this function will return true. Otherwise, it will return false.
IsAlertTriggered Returns a true or false value, depending on whether the record the formula is evaluating for triggers the alert or not. For example, if you create a formula containing the IsAlertTriggered ( Order Exceeds 5,000 ) function, the function will return true for records with order amounts greater than $5,000, and false for records with order amounts equal to or less than $5,000.
AlertMessage Returns the message specified for the Report Alert. This is either the hard-coded message that was typed into the Message text box when the alert was created, or the results of the message string formula that was created with the alert.
For the previously discussed customer subtotal example, you may wish to create a formula that displays a message in group footers that trigger the alert. The formula might look similar to this:
If IsAlertTriggered ("Beat 2000 Goal") Then
GroupName ({Customer.Customer Name}) & " beat the 2000 goal"
You may also wish to highlight the entire group footer with a different background color if the group triggered a Report Alert. You can use these new formula functions in conditional formatting formulas, as well as report formulas. For example, you could conditionally set the background color of the Customer Name Group Footer to aqua by using the Section Expert. The conditional formula would be similar to this:
If IsAlertTriggered ("Beat 2000 Goal") Then crAqua Else crNoColor
Note | For complete information on formatting sections and the Section Expert, refer to Chapter 10. |