MaxObject API
On the Max platform, when you use SMQL, records handled by the platform are instances of the MaxObject class. When you execute SMQL logic to create, update, delete, or query records, instances of the MaxObject class are retrieved. Additionally, when Validator or Event Handler code is invoked, the records retrieved are instances of MaxObject (recordUnderValidation for Validators and affectedMaxObject for Event Handlers).
You can this API to provide information about metadata, field changes, validation, and serialization for records.
Metadata-Related Methods
getDefinition
Retrieves the metadata definition associated to a specified record.
Examples
Allow the associated metadata definition for the Object associated with a record:
def definition = record.getDefinition()
Retrieve the object’s full identifier:
definition.getFullIdentifier()
Define whether a specified field is associated with an object:
definition.hasFieldDefinition("io_showcase_integer")
Retrieves the data type of a field:
definition.getFieldDefinition("io_showcase_integer").getDatatype()
Field Changes-Related Methods
changed()
Indicates whether any of the fields of a specified record have changed since the beginning of a transaction.
Use this method to check whether records received by validators, event handlers, or operations have changed. You can check for changes at the record and field levels and retrieve previous field values.
Example
def record = Database.querySingleResult("select * from io_showcase where io_uuid = '42f64596-c42f-4ba2-8138-cc40188d2a88'")
record.io_showcase_integer = 100
Database.update(record)
record.changed() //will return true
isFieldChanged()
Determines whether a particular field changed in a record.
Example
def record = Database.querySingleResult("select * from io_showcase where io_uuid = '42f64596-c42f-4ba2-8138-cc40188d2a88'")
record.io_showcase_integer = 1500
Database.update(record)
record.isFieldChanged("io_showcase_integer") //will return true
getChangedFields()
Determines whether a set of fields changed in a record.
Example
def record = Database.querySingleResult("select * from io_showcase where io_uuid = '42f64596-c42f-4ba2-8138-cc40188d2a88'")
record.io_showcase_integer = 1200
record.io_name = "new name"
Database.update(record)
record.getChangedFields() //returns a map with the changed fields, the key is the field's UUID and the value is the new value
getOldFieldValue
Retrieves the previous value of a specified field that was changed during the current transaction.
Example
def record = Database.querySingleResult("select * from io_showcase where io_uuid = '42f64596-c42f-4ba2-8138-cc40188d2a88'")
record.io_name = "my new name"
Database.update(record)
record.getOldFieldValue("io_name") // returns the value before the change
Validation-Related Methods
isvalid()
Checks whether validation checks on a specified record have passed.
* 
The Max platform automatically validates records before data is persisted to the database.
Example
def record = Database.querySingleResult("select * from io_showcase where io_uuid = '42f64596-c42f-4ba2-8138-cc40188d2a88'")
record.io_name = ""
record.isValid() //returns false as the io_name field is required
Serialization-Related Methods
serialize()
Serializes a specified record by using serialization logic on the default platform.
* 
The Max platform automatically serializes records generated during an operation, if the operation is configured to do so.
Example
def record = Database.querySingleResult("select * from io_showcase where io_uuid = '42f64596-c42f-4ba2-8138-cc40188d2a88'")
record.serialize() //this will return the JSON containing the full serialized entity
setFieldsToSerialize()
Serializes a subset of fields before serializing a specified record.
Example
def record = Database.querySingleResult("select * from io_showcase where io_uuid = '42f64596-c42f-4ba2-8138-cc40188d2a88'")
record.setFieldsToSerialize(["io_uuid", "io_name"])
record.serialize() //this will return the JSON containing only the fields indicated plus a subset of platform fields
Other Helpful Methods
record.isBeingDeleted()
Indicates whether the record is being deleted during the current transaction.
record.getPrimaryName()
Returns the record’s primary name.
For more information:
Was this helpful?