Crystal Reports for Eclipse Designer Guide

Understanding conditional attribute properties

A conditional attribute property tests to see which of two or more conditions is met. The program then applies the formatting appropriate to the condition. For example, assume that you want values under quota printed in red and all other values printed in black. The program tests to see whether the value is under quota or not. If it is under quota, then it applies the red attribute; if it is not, then it applies the black attribute.
Use an If-Then-Else formula for this kind of conditional formatting.
Crystal syntax example
If {CUSTOMER.LAST_YEARS_SALES} > 5000 Then
     crRed
Else
     crBlack
When you create formulas for conditional attribute properties, Crystal Reports shows you a selection of attributes in the formula comments area within the Formulas view. You can use any of these attributes in your formula. For example, if you are setting a background color conditionally, the selection contains attributes for each color that you can use. If you are setting borders conditionally, the selection contains attributes such as crSingleLine, crDoubleLine, crDashedLine, crDottedLine, and crNoLine.

Note: Always include the Else keyword in conditional formulas; otherwise, values that don't meet the If condition may not retain their original format. To retain the original format of values that don't meet your If condition, use the DefaultAttribute function. The DefaultAttribute function returns the value of the formatting property set in the "Properties" view.
Crystal syntax example
If {CUSTOMER.LAST_YEARS_SALES} > 5000 Then
     crRed
Else
     DefaultAttribute
You can take this kind of property one step further. You can specify a list of conditions and a property for each; you are not limited to two conditions. For example, if you have a number field on your report that contains sales figures from countries around the world, you can specify the number attribute(s) that you want to apply to each country. In this case, your conditions would specify that if it is from Country A, the program should apply the Country A attribute; if it is from Country B, the Country B attribute; if it is from Country C, the Country C attribute, and so on.
With more than two alternatives, use this kind of formula:
Crystal syntax example
If {CUSTOMER.Country} = "Canada" Then
     crRed
Else If {CUSTOMER.Country} = "England" Then
     crBlack
Else If {CUSTOMER.Country} = "Australia" Then
     crGreen
Else
     crBlue
Use a multi-condition If-Then-Else formula for this kind of conditional formatting.



SAP BusinessObjects
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Product Documentation on the Web
http://help.sap.com/