Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

8.12 Using Alerts in Formulas

Using Alerts in Formulas

Crystal Reports gives you functions that let you work with alerts. You can find out if alerts are enabled, which records trigger the alert, and what the alert message is. The alert functions are listed in Table 8-2.

Table 8-2. Report alert functions.

Function Description
IsAlertEnabled(“AlertName”) Returns True if the Enable Alert checkbox is checked. Otherwise returns False.
IsAlertTriggered(“AlertName”) Returns True if the current record meets the condition in the report alert.
AlertMessage(“AlertName”) Returns the message associated with the report alert.

Since a report can have more than one alert, each alert function is passed the alert name that you are inquiring about. This is a string value enclosed in quotes. By combining these alert functions with conditional formatting, you can add special formatting to the report rows that triggered the alert. This benefits the user because if they are looking at the full report then they will still know which records meet the alert condition. For example, by associating the following formula with the font color of the sales amount, records that trigger an alert are shown in red.

If IsAlertEnabled(“Sales”) and IsAlertTriggered(“Sales”) Then
crRed
Else
DefaultAttribute;

The first line tests whether the alert is enabled and whether the current record triggered it. If both of these conditions are true, then the font color crRed is returned. If either one of these conditions isn’t met, then the font color stays the same. This is because either the alert isn’t turned on or the record didn’t trigger it. Either way, you want the font to remain unchanged.

In one respect, these alert functions in Table 8-2 aren’t completely necessary because you could have just used the same logic from the report alert in the conditional formatting formula. This would give you the same results because the conditional formatting would still modify the report object when necessary. The benefit of using the alert functions is that you aren’t duplicating the same logic in two different places. If you need to go back to modify the report alert, then the conditional formatting will still work properly. If you had retyped the same logic in both places, then updating the report alert would mean that you have to remember to update the conditional formatting logic also. If you forget to do both, then the report formatting won’t be correct.

As a general rule, you always want to share formula logic whenever possible because not doing so makes it easier to make mistakes.