Defining Calculated Fields
The following example shows how to define a field to calculate the difference in hours from the time of record creation to the most recent update. You can use this logic to calculate time differences between fields with the Timestamp data type.
To define a calculated field:
1. In an Object record, create a new field, and be sure to select the Calculated check box and the appropriate data type for the resulting calculated value.
2. Save the field, and then in
Max Designer, on the
Development Actions (
) launchpad menu, click
Synchronize.
3. Open the field, and then in the Code tab, in the System Code field, add Groovy code, for example:
import org.joda.time.DateTime
import org.joda.time.Duration
def now = new DateTime();
def someDateTimeField = io_created_on
Duration duration = new Duration(someDateTimeField, now);
duration.getStandardHours()
| This code gets the field value of io_created_on from the current record. |
4. In
Form Designer, add the new field to the record creation form for the relevant object, and then on the
Development Actions (
) launchpad menu, click
Synchronize.
For more information: