Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

CRM Audit History

Posted on by Microsoft Employee

I wanted to retrieve the 'statuscode' audit history for the incident.

I have got the AuditDetailCollection, how do I retrieve the value of the statuscode?

Thanks.

code snippet:

var attributeChangeHistoryRequest = new RetrieveAttributeChangeHistoryRequest()
{
Target = new EntityReference("incident", _case.Id),
AttributeLogicalName = "statuscode"
};

var attributeChangeHistoryReponse = (RetrieveAttributeChangeHistoryResponse)_service.Execute(attributeChangeHistoryRequest);
var auditDetailCollection = attributeChangeHistoryReponse.AuditDetailCollection;

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Audit History

    I got the solution, posted here just in case someone might need it fro reference, make sure the detailType is of AttributeAuditDetail which expose the status attribute.

    var auditDetailsAsc = auditDetailCollection.AuditDetails.OrderBy(x => x.AuditRecord.GetAttributeValue<DateTime>("createdon"));//Asc order

    foreach (var auditDetail in auditDetailsAsc)

               {

                   var detailType = auditDetail.GetType();

                   if (detailType == typeof(AttributeAuditDetail))

                   {

                       var attributeDetail = (AttributeAuditDetail)auditDetail;

                       OptionSetValue auditStatusOldValue = attributeDetail.OldValue.GetAttributeValue<OptionSetValue>("statuscode");

                       OptionSetValue auditStatusNewValue = attributeDetail.NewValue.GetAttributeValue<OptionSetValue>("statuscode");

                       DateTime auditCreatedon = attributeDetail.AuditRecord.GetAttributeValue<DateTime>("createdon");

    .....

    ........

    ........

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Audit History

    There's is no auditDetailCollection.Entities

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Audit History

    Use below code:

    if (auditDetailCollection  != null && auditDetailCollection.Entities != null && auditDetailCollection.Entities.Count > 0)

                   {

                       foreach (Entity current in auditDetailCollection.Entities)

                       {

                           if (current.Attributes.Contains("statecode") && current.Attributes["statecode"] != null)

                           {

    int statecode = ((OptionSetValue)current.Attributes["statecode"]).Value;

    }

                       }

                   }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans