Configurable Formula functionality uses the same expression syntax and conventions supported in Configurable Validations. Please refer to the “Writing a Configurable Validation” topic for various conventions supported by the system. In addition, formula expression can include simple JAVA style if/else and for/while loop statements to run logic and derive a final field value.
Formula expression is a collection of statements and when multiple statements are included in the expression, the result evaluated from the last statement execution will be used as the field value where the formula is configured.
Examples:
If a business object has RATE, QUANTITY, DISCOUNT, and FINAL_AMOUNT fields and formula defined on FINAL_AMOUNT as shown below, it is considered a single statement expression. In the following example, the value derived by evaluating the expression will be set on the formula field.
(RATE * QUANTITY) – (RATE * QUANTITY * DISCOUNT)
Performance Budgeting amount fields need to typecasted to BigDecimal.
(new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity)) – (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”,quantity) * new(“java.math.BigDecimal”,discount))
If a business object has RATE, QUANTITY, and FINAL_AMOUNT fields and formula defined on FINAL_AMOUNT to calculate an amount using variable discount it is considered a multiple statement expression as shown below.
If (QUANTITY > 500) {
(RATE * QUANTITY) - (RATE * QUANTITY * 0.10)
} else if (QUANTITY > 250) {
(RATE * QUANTITY) - (RATE * QUANTITY * 0.08)
} else {
(RATE * QUANTITY) - (RATE * QUANTITY * 0.05)
}
Performance Budgeting amount fields need to typecasted to BigDecimal.
If(quantity > 500){
(new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity)) – (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity) * 0.10)
} else if(quantity > 250){
(new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity)) – (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity) * 0.08)
} else {
(new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity)) – (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity) * 0.05)
}
In the above example, the field value is evaluated to the last statement executed based on the QUANTITY value. In multiple statement scenarios, you can optionally use a JAVA style return keyword with a semi-colon to break the expression execution. The previous expression can be written as shown below and works perfectly fine.
If (QUANTITY > 500) {
return (RATE * QUANTITY) - (RATE * QUANTITY * 0.10);
} else if (QUANTITY > 250) {
return (RATE * QUANTITY) - (RATE * QUANTITY * 0.08);
} else {
return (RATE * QUANTITY) - (RATE * QUANTITY * 0.05);
}
Performance Budgeting amount fields need to typecasted to BigDecimal.
If(quantity > 500){
return (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity)) – (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity) * 0.10)
} else if(quantity > 250){
return (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity)) – (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity) * 0.08)
} else {
return (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity)) – (new(“java.math.BigDecimal”,rate) * new(“java.math.BigDecimal”, quantity) * 0.05)
}