Using Boolean expressions
A Boolean expression returns one of two values: true or false. The following expressions are basic Boolean expressions:
row["sales"] > 5000
row["state"] == "CA"
row["orderDate"] >= new Date(2005, 4, 30)
The first expression tests if the sales value is greater than 5000. If so, the expression returns true. If it is not, the expression returns false.
The second expression tests if the state value is equal to CA. If the value is CA, the expression returns true; if not, the expression returns false. For Boolean expressions, you must use comparison operators. As the second expression shows, you use ==, not the assignment operator, =. The expression row["state"] = "CA" returns CA. It does not return a true or false value.
The third expression tests if the order date is greater than or equal to the date April 30, 2005.
A Boolean expression can be as complex as you need. It can contain a combination of && (AND) and || (OR). The following expressions are examples of complex, or compound, Boolean expressions:
The following expression returns true if an order total is greater than or equal to 5000 and an order ID is greater than 2000. Both conditions must be true.
row["orderTotal"] >= 5000 && row["orderID"] > 2000
The following expression returns true if the state is CA or WA. Only one condition needs to be true.
row["state"] == "CA" || row["state"] == "WA"
The following expression returns true if three conditions are true:
The state is CA or WA.
The order total is greater than 5000.
The order ID is greater than 2000.
(row["state"] == "CA" || row["state"] == "WA") && (row["orderTotal"] > 5000 && row["orderID"] > 2000)
Use a Boolean expression to:
Conditionally display a report element.
Specify conditions with which to filter data.
Specify conditions with which to perform particular tasks. For example, use a Boolean expression in an if statement to do something when the expression is true and to do something else when the expression is false, as shown in the following example:
if (row["creditScore"] > 700) {
displayString = "Your loan application has been approved."
}
else{
displayString = "Your loan application has been denied."
}
You seldom use a Boolean expression on its own unless you want to display true or false in the report.