Hi,
It will work for Auditdetailscollection as well.
Please see sample code providd below which is working code and does return display name of the field.
RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest();
changeRequest.Target = new EntityReference("contact", new Guid("9e4967da-8ee4-eb11-bacb-0022486e98df"));
RetrieveRecordChangeHistoryResponse changeResponse = (RetrieveRecordChangeHistoryResponse)crmSvc.Execute(changeRequest);
AuditDetailCollection auditDetailCollection = changeResponse.AuditDetailCollection;
foreach (AttributeAuditDetail attrAuditDetail in auditDetailCollection.AuditDetails)
{
var auditRecord = attrAuditDetail.AuditRecord;
string entityName = ((EntityReference)auditRecord.Attributes["objectid"]).LogicalName;
Console.WriteLine("Entity: " + ((EntityReference)auditRecord.Attributes["objectid"]).LogicalName);
Console.WriteLine("Operation: " + auditRecord.FormattedValues["operation"]);
Console.WriteLine("Action: " + auditRecord.FormattedValues["action"]);
var newValueEntity = attrAuditDetail.NewValue;
foreach (var attrNewValue in newValueEntity.Attributes)
{
Console.WriteLine("New Key: " + attrNewValue.Key + " New Value: " + attrNewValue.Value);
Console.WriteLine("New Key: " + RetrieveAttributeDisplayName(entityName, attrNewValue.Key, crmSvc) + " New Value: " + attrNewValue.Value);
}
var oldValueEntity = attrAuditDetail.OldValue;
foreach (var attrOldValue in oldValueEntity.Attributes)
{
Console.WriteLine("Old Key: " + attrOldValue.Key + " Old Value: " + attrOldValue.Value);
Console.WriteLine("Old Key: " + RetrieveAttributeDisplayName(entityName, attrOldValue.Key, crmSvc) + " Old Value: " + attrOldValue.Value);
}
}
you can copy RetrieveAttributeDisplayName method code from my previous link.
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/