web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How To get the Display Name of field when we fetch the "AuditDetailCollection" of opportunity entity.

(0) ShareShare
ReportReport
Posted on by 23

How To get the  Display Name of field  when we fetch the  "AuditDetailCollection" of opportunity entity.

This is my code:--

RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest();
changeRequest.Target = new EntityReference("opportunity", opportuntiyid);
RetrieveRecordChangeHistoryResponse changeResponse = (RetrieveRecordChangeHistoryResponse)service.Execute(changeRequest);
AuditDetailCollection details = changeResponse.AuditDetailCollection;

  • Suggested answer
    Bipin D365 Profile Picture
    28,995 Moderator on at

    Hi,

    You will need to query metadata to get displayname using field schema name. See below code which does the same thing.

    vishalgrade.com/.../

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Rahul Rathore Profile Picture
    23 on at

    Hi Bipin,

    That is for entity collection not for auditdatacollection.

  • Suggested answer
    Bipin D365 Profile Picture
    28,995 Moderator on at

    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/

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 102

#2
11manish Profile Picture

11manish 88 Super User 2026 Season 2

#3
ParthPatel249 Profile Picture

ParthPatel249 84

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans