Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Fetch record audit history using RetrieveAuditDetailsRequest in C#

Posted on by

I am trying to fetch the audit history of a user from CRM. My code is shown below. However at run time i get an exception "audit With Id = c011f583-8741-e211-bce3-78e7d1622fbb Does Not Exist".

Am I missing something?. Please suggest.

Entity entUser = (from name in context.CreateQuery(Constant.SystemUser.EntityLogicalName)

                                  where name.GetAttributeValue<string>(Constant.SystemUser.FullName) == "Sample"

                                  select name).FirstOrDefault();

 

var auditDetailsRequest = new RetrieveAuditDetailsRequest

                {

                    AuditId = entUser.Id

                };

using (OrganizationServiceProxy organizationProxy = CRMHelper.GetServiceProxy())

                {

                    var auditDetailsResponse = organizationProxy.Execute(auditDetailsRequest);

                }

*This post is locked for comments

  • Suggested answer
    Siraj M Profile Picture
    Siraj M on at
    RE: Fetch record audit history using RetrieveAuditDetailsRequest in C#

    if you want to retrieve audit details based on the audit id then you can use RetrieveAuditDetailsRequest.

    but here you are trying to retrieve audit details based on user id then you need to use RetrieveRecordChangeHistoryRequest

    RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest(); changeRequest.Target = new EntityReference("systemuser", entUser.Id);



    we also have RetrieveAttributeChangeHistoryRequest SDK request to retrieve audit details for a specific attribute

    var attributeChangeHistoryRequest = new RetrieveAttributeChangeHistoryRequest
                {
                    Target = new EntityReference(
                           "incident", new Guid("D22F869B-F79C-E611-80F0-3863BB35EF70")),
                    AttributeLogicalName = "statuscode"
                };


     Regards,

    Siraj

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Fetch record audit history using RetrieveAuditDetailsRequest in C#

    It because you're trying to use id of your user, but AuditId parameter -  the ID of the Audit record to retrieve

    If you want to get history of changes use RetrieveRecordChangeHistoryRequest (https://msdn.microsoft.com/en-us/library/gg309735.aspx)

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans