If Expressions
There is something that looks like a predefined formula that you can use if you need to include a decision in your formula.
For example, suppose that the value of a field represents a 10% surcharge on amounts greater than $100. For amounts less than $100, the surcharge is zero. Write this as
If(amount>100,amount*0.10,0)
The first input for if is something that is either true or false. If the first input is true, the value of the if’s second input is the value of the if. If the first input is false, the value of the if’s third input is the value of the if.
There are a few things about if that make it different. The first argument is that if the if expression can contain the four arithmetic operators, it can also contain other operators, like comparison operators.
The following list contains all of the operators that you can use with both extended formulas and workflow expressions:
Operator | Description |
---|---|
( ) - + / * == != < <= > >= && || |
open parenthesis close parenthesis subtraction addition division multiplication is equal to is not equal to is less than is less than or equal to is greater than is greater than or equal to and or |
Another thing different about if is when the values of its inputs are computed. For regular predefined formulas, the values of all their inputs are computed and then the value of the predefined formula is computed.
For an if, the value of its first input is computed first. If the value of the first input is true, the value of the second input is computed; if the value of the first input is false, the value of the third input is computed. This means that depending on the value of the first input, the value of either the second or third input is not computed.
Each time the value of an if is computed, the value of either its second or third input is not computed. For most formulas, this fact is not important. However, there are some formulas for which this is crucial.
According to the rules for arithmetic, you are not allowed to divide by zero. Because of this rule, if a division operator in a formula tries to divide zero, it is not possible to compute a value for the formula. There are input values that can prevent Maximo® Real Estate and Facilities from computing the result of a predefined formula. If the result of a formula cannot be computed, Maximo Real Estate and Facilities uses zero as its result. If you need a value other than zero, the way that the inputs of an if are computed becomes important.
Here is an example of a formula that can be made to work only by taking advantage of the fact that the value of one of an if’s inputs is not computed: Suppose that you need to compute a value for a field named Aspect Ratio. The value of Aspect Ratio is Height/Width unless the value of width is zero. If the value of Width is zero, the result of Aspect Ratio is to be 999999999.
The only way to write a formula that does this computation is to use if. Taking advantage of the fact that if does not compute the value of one of its inputs avoids a division by zero. The formula must avoid division by zero, otherwise its result is forced to be zero rather than 999999999. Write the formula for Aspect Ratio as if(width#0,Height/Width,999999999). You can read this as If width not equal to zero then Height divided by Width else 999999999.