ObjectChangeLog Methods

Message Transformation dynamic logic functions provide access to ObjectChangeLog via dynamic logic binding parameter objectChangeLog. ObjectChangeLog contains the changes that triggered the message generation. ObjectChangeLog provides number of api’s to get access to the change log. It can be used to get the information about created, updated and deleted objects. ObjectChangeLog provides following apis to access the changes:

ObjectChangeLog Methods

getChangedEntityNames()

Returns the set of entity names that has at least one created/updated/deleted record change.

getRecords(String entityName)

Returns the list of object changes for the entityName provided as parameter. It includes created, updated and deleted object changes.

getRecords(String entityName, Long id)

Returns the list of object changes for the entityName and id provided as parameter. It includes the records that created, updated and deleted for the id.

getAttributeChange(String entityName, Long id, String attributeName)

Returns the attribute change for attributeName of provide entityName and record id. Returns the attribute change, if there are any updates on the attribute otherwise returns null. In create/delete scenarios, always returns null.

ObjectChange Methods

ObjectChange is a sub view model, that provide access to the changes of one record.

isCreate

Returns true If the change is for object create.

isUpdate

Returns true if the change is for object update.

isDelete

Returns true if the change is for object delete.

getId

Returns the id of the changed object.

getCode

Returns the code of changed object, if the changed object has code attribute. Only applicable for created and deleted changes.

getAttributeChanges

Returns the map of object attribute changes. Each map entry key is attributename and the value is the attribute change object.

AttributeChange Methods

AttributeChange is a sub view model, that provide access to the changes of a single attribute.

getOldValue

Returns the old value of the attribute. This method is available for String, Number, Date, Money and reference type fields. Reference type fields return object attributes of type object.

getNewValue

Returns the new value of the attribute. This method is available for String, Number, Date, Money and reference type fields. Reference type fields return object attributes of type object.

getObjectChanges

Returns the List of ObjectChange. This method is available for dynamic records and multi-value/time-valid dynamic field attributes.

getAddedValues

Returns the List of added objects.

getRemovedValues

Returns the List of removed objects.

ObjectAttribute Methods

ObjectAttribute is used to represent the reference field types.

getId

Returns the id of reference object.

getCode

Returns the code of reference object, if it is available.

Examples

Above api’s can be used for lot of use cases, some of the examples are below:

Usecase: If you want to perform some action(s), only if there are any changes in EnrollmentProduct entity.

if( objectChangeLog.getChangedEntityNames().contains("EnrollmentProduct") ) {
     // only execute these statements, if there are any changes in EnrollmentProduct
}

Usecase: If you want to perform some action(s), only if EnrollmentProduct is created, updated or deleted.

def changedRecords = objectChangeLog.getRecords("EnrollmentProduct")

boolean recordsCreated = false
boolean recordsUpdated = false
boolean recordsDeleted = false

for(change in changedRecords) {
  if(change.isCreate()) {
       recordsCreated = true
   } else if (change.isUpdate()) {
       recordsUpdated = true
  } else {
       recordsDeleted = true
  }
}

if(recordsCreated) {
    // only execute these statements, if an EnrollmentProduct is created.
}

if(recordsUpdated) {
    // only execute these statements, if an EnrollmentProduct is updated.
}

if(recordsDeleted) {
    // only execute these statements, if an EnrollmentProduct is deleted.
}

Usecase: Let’s say, if status attribute is updated on enrollment product with id 2, the old and new value of the attribute can be accessed using below example. This example can be used, if the attribute type is string, number, money and date.

def attributeChange = objectChangeLog.getAttributeChange("EnrollmentProduct", 2L, "status")
def oldValue = attributeChange.getOldValue()
def newValue = attributeChange.getNewValue()

Usecase: Let’s say, we have a dynamic record called "record1" on the EnrollmentProduct and a new entry is added, it can be accessed using the object changes on api on AttributeChange.

def attributeChange = objectChangeLog.getAttributeChange("EnrollmentProduct", 2L, "record1")
def record1AttributeChanges = attributeChange.getObjectChanges()
// record1AttributeChanges is a list of changes made in record1 for EnrollmentProduct with id 2.

Usecase: If multiple attributes are updated for same record, they can be accessed using the above example but it is also possible to get the map of all the changed attributes.

// A record changes can be accessed using getRecords api. Only update is needed, list can be filtered using stream
def updatedObject = null
def changedRecords = objectChangeLog.getRecords("EnrollmentProduct")

for(change in changedRecords) {
  if (change.isUpdate()) {
    updatedObject = change
    break
  }
}

// if update is always expected no need to add null checks, otherwise handle null situations,
// changedAttributes map contains all the changed attributes. map get operation can be used to get individual attribute change

def changedAttributes = updatedObject.getAttributeChanges()