Calculated Fields Code Examples
The following examples are for a calculated field in an object named Showcase, which has at least one field for every data type with full identifiers such as io_showcase_integer, io_showcase_string_localized, io_showcase_option_list, and so on.
|
The Test Calculated Field Code option on the Development Actions ( ) launchpad menu in Max Designer is a prototype developer tool for testing this code. |
Sample Data
io_showcase_currency_amount: 248.00 USD
io_showcase_date: 2012-12-11
io_showcase_integer: 42
io_showcase_number: 3.1426
io_showcase_string: Sample Text
io_showcase_text: Sample Text
io_showcase_timestamp: 2012-12-10T18:04:00.000-08:00
Before you review the following examples, see
SMQL Field Data Types.
Concatenate Two Strings
io_showcase_string + " and " + io_showcase_text
Return Value
Showcase String and Showcase Text
Add Two Integers/Numbers
io_showcase_number + io_showcase_integer
Return Value
45.1426
Add a String and a Number
"Hello " + 4242 + " Hello"
Return Values
Hello 4242 Hello
Multiply a Number and a Currency Amount
io_showcase_currency_amount.getValue() * io_showcase_number
Return Value
779.3648
Get the Earlier of Two Dates
date1=io_showcase_datedate2=io_showcase_timestamp.toLocalDate()date1.isBefore(date2) ? date1 : date2
Return Value
2012-12-10
Get the Difference Between the Previous and Updated Values of an Integer
old_value = getOldFieldValue("io_showcase_integer")
new_value = io_showcase_integer
new_value - old_value
Return Value
0
Get the Difference in Days/Hours/Minutes Between the someDateTime Field Value and the Current Time
def today = new org.joda.time.DateTime();
def someDateTimeField = io_created_on
org.joda.time.Duration duration = new org.joda.time.Duration(someDateTimeField, today);
//duration.getStandardDays();
//duration.getStandardHours();
duration.getStandardMinutes();
For more information: