Hello everyone my name is Taniguchi
I'm using C# plugin to retrieve audit history for the opportunity entity and i wish to retrieve every field that were changed and i was able to retrieve audit details like creadon, action and operation now I wish to retrieve the fields that were changed and old and new value. How could can i get this values in plugin ?
My code so far:
string EntitySchemaName = "opportunity"; foreach (var opportunityRecords in result.Entities) { string opportunityGUID = opportunityRecords.Attributes["opportunityid"].ToString(); string opportunityNumber = opportunityRecords.Attributes["vale_opportunitynumber"].ToString(); Guid _opportunityID = new Guid(opportunityGUID); // Retrieve the audit history for the account and display it. RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest(); changeRequest.Target = new EntityReference(EntitySchemaName, _opportunityID); RetrieveRecordChangeHistoryResponse changeResponse = (RetrieveRecordChangeHistoryResponse)organizationService.Execute(changeRequest); AuditDetailCollection details = changeResponse.AuditDetailCollection; foreach (var attrAuditDetail in details.AuditDetails) { var detailType2 = attrAuditDetail.GetType(); if (detailType2 == typeof(Microsoft.Crm.Sdk.Messages.AttributeAuditDetail)) { Microsoft.Crm.Sdk.Messages.AttributeAuditDetail attributeDetail = (Microsoft.Crm.Sdk.Messages.AttributeAuditDetail)attrAuditDetail; //Details of Audit var auditDetailsRequest = new Microsoft.Crm.Sdk.Messages.RetrieveAuditDetailsRequest { AuditId = attributeDetail.AuditRecord.Id }; var auditDetailsResponse = (Microsoft.Crm.Sdk.Messages.RetrieveAuditDetailsResponse)organizationService.Execute(auditDetailsRequest); if (auditDetailsResponse != null && auditDetailsResponse.AuditDetail != null && auditDetailsResponse.AuditDetail.AuditRecord != null) { Microsoft.Xrm.Sdk.Entity auditEntity = auditDetailsResponse.AuditDetail.AuditRecord; if (auditEntity.Attributes.Contains("createdon")) { Console.WriteLine(string.Format("Audit2 CreatedOn {0}", auditDetailsResponse.AuditDetail.AuditRecord.Attributes["createdon"])); } } } } }