Change Logs and Enrollment Change Events
The message transformation dynamic logic functions grant access to the ObjectChangeLog through the dynamic logic binding parameter objectChangeLog. This log contains the changes that triggered message generation and offers various APIs to retrieve information about change logs and to get information on created, updated, and deleted objects. The ObjectChangeLog provides the 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.
PolicyEnrollmentEventKey Methods
PolicyEnrollmentEventKey is a subview model that contains information about the entity that is subject to the policyEnrollmentEvent
ObjectChangePolicyEnrollmentEvent Methods
ObjectChangePolicyEnrollmentEvent is a subview model which extends the ObjectChange class, providing access to changes of one record.
getTriggeringObject
Returns the object that got changed as follows:
- 
In case of a fixed field attribute change or a single-value non-time-valid (SVNTV) dynamic field, this will return the parent entity of that fixed field or SVNTV dynamic field.
 - 
In case of a multivalue time-valid (MVTV) or non-time-valid change to a single-value time-valid (SVTV) attribute, this will return the dynamic object, not the parent entity object.
 
Consider the following example payload for policyEnrollmentProduct:
{
    "policyEnrollmentProductList": [
        {
            "SVNTV_DRD_CMN_KEY": {
                "code": "string1",
                "encoding": 1,
                "effectiveDate": "2015-07-20",
                "eyeColor": {
                    "value": "RED"
                }
            },
            "SVTV_DRD_CMN_KEY": [
                {
                    "code": "string23",
                    "endDate": "2015-07-20",
                    "encoding": 1,
                    "effectiveDate": "2016-07-20",
                    "startDate": "2015-07-20",
                    "eyeColor": {
                        "value": "BROWN"
                    }
                }
            ],
            "SVTV_CHAR": [
                {
                    "endDate": "2016-07-20",
                    "startDate": "2015-07-20",
                    "value": "someText-new2 3"
                }
            ],
            "SVNTV_CHAR": "someText - updated2 new123",
            "MVTV_CHAR": [
                {
                    "endDate": "2016-07-21",
                    "startDate": "2015-07-20",
                    "value": "someValue new"
                }
            ],
            "MVNTV_CHAR": [
                {
                    "value": "someVAlue1 upd"
                },
                {
                    "value": "someVAlue2- updated2"
                }
            ],
            "startDate": "2024-01-01",
            "enrollmentProductCode": "ENPR_001",
            "endDate": "2025-01-04"
        }
    ]
}
In case of a fixed field change, such as startDate and endDate of enrollmentProductCode, the entire parent entity object, which is policyEnrollmentProduct, will be returned.
In case of a single value non-time-valid dynamic field change, such as SVNTV_CHAR, the entire parent entity object, which is policyEnrollmentProduct, will be returned.
In all other cases, such as MVNTV_CHAR, MVTV_CHAR, SVTV_DRD_CMN_KEY, SVNTV_DRD_CMN_KEY, and SVTV_CHAR, the corresponding dynamic object is returned.
Examples
Above api’s can be used for lot of use cases, some of the examples are below:
Usecase: 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: 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: Take an example of 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()