ian.blair@softstuff

My technical musings

Getting Audit data out of CRM

When retrieving Audit Log information from Dynamics 365 using 

RetrieveAttributeChangeHistoryRequest attributeChangeHistoryRequest =
                            new RetrieveAttributeChangeHistoryRequest {
                                Target = new EntityReference(Contact.EntityLogicalName, contact.Id),
                                AttributeLogicalName = "new_myfield",
                            };

RetrieveAttributeChangeHistoryResponse attributeChangeHistoryResponse =
                            (RetrieveAttributeChangeHistoryResponse) context.Execute(attributeChangeHistoryRequest);

 

The returned data in the AuditDetails collection will contain an action attribute, this will determine the type of operation that took place.

       foreach (var EachEditRecord in attributeChangeHistoryResponse.AuditDetailCollection.AuditDetails)
       {
             AuditDetail attributeDetail = (AuditDetail) EachEditRecord;
             OptionSetValue action = (OptionSetValue) attributeDetail.AuditRecord["action"];
        }

 

A list of actions are below