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.
ObjectChange Methods
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.
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()