Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

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

Posted on by 119

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;

Categories:
  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,958 Super User on at
    RE: How To get the Display Name of field when we fetch the "AuditDetailCollection" of opportunity entity.

    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/

  • Rahul Rathore Profile Picture
    Rahul Rathore 119 on at
    RE: How To get the Display Name of field when we fetch the "AuditDetailCollection" of opportunity entity.

    Hi Bipin,

    That is for entity collection not for auditdatacollection.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,958 Super User on at
    RE: How To get the Display Name of field when we fetch the "AuditDetailCollection" of opportunity entity.

    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/

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans