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

Delete audit logs for a specific entity and before a specific date

(1) ShareShare
ReportReport
Posted on by 119
Hi
I've been able to retrieve Audit log GUIDs which meet criteria of a particular entity and a date prior to, but can't see how to delete them, as Delete method does not support entities of type Audit.
 
Any thoughts?
I have the same question (0)
  • Suggested answer
    Leah Ju Profile Picture
    Microsoft Employee on at
    Hi,
    Dataverse auditing supports the deletion of a single record's entire audit history. 
    Please refer to the following:
    1.Go to settings > Auditing > Audit Log management.
    2.The following page will be opened, and you can select audit logs to delete in the right pane.

    I hope you can mark my answer verified if it answer your question! If you have any questions, please feel free to contact me.
    Regards,
    Leah
     
  • simonsnell Profile Picture
    119 on at
    Hi  @Leah Ju
    Thanks
    This will remove ALL of the audit from that particular table.  However, I only want to remove audit logs, as an example, for Contacts but before 1/1/2021.
    I don't think this is possible.
  • Suggested answer
    LuisAvitia Profile Picture
    4 on at
    Hello 
    You can use the SDK, create a console to delete the audit and search the audit by Action, Date, or Entity or as needed.
     
    You just have to create the QueryExpression as you require for your audit search and it will delete those records that are obtained.
     
    /// <summary>
    /// Creates a BulkDelete job to delete audit record history for a 
    /// specific action and shows the job created.
    /// </summary>
    /// <param name="svc">IOrganizationService to use</param>
    /// <param name="actionValue">The audit action value</param>
    static void BulkDeleteAuditHistoryByAction(IOrganizationService svc, int actionValue)
    {
        Guid jobId;
        var querySet = new QueryExpression(entityName: "audit");
        querySet.Criteria.AddCondition(
            attributeName: "action",
            conditionOperator: ConditionOperator.Equal,
            values: actionValue);
        var req = new BulkDeleteRequest
        {
            QuerySet = new QueryExpression[] { querySet },
            JobName = $"Bulk Delete of audit records with action = {actionValue}",
            SendEmailNotification = false,
            ToRecipients = new Guid[] { },
            CCRecipients = new Guid[] { },
            RecurrencePattern = string.Empty,
            StartDateTime = DateTime.UtcNow
        };
        try
        {
            var resp = (BulkDeleteResponse)svc.Execute(req);
            jobId = resp.JobId;
            Entity bulkDeleteJob =
                svc.Retrieve(
                    entityName: "asyncoperation",
                    id: jobId,
                    columnSet: new ColumnSet("name", "statecode", "statuscode"));
            Console.WriteLine($"Job Name: {bulkDeleteJob["name"]}");
            Console.WriteLine($"Job Id: {bulkDeleteJob.Id}");
            Console.WriteLine($"State: {bulkDeleteJob.FormattedValues["statecode"]}");
            Console.WriteLine($"Status: {bulkDeleteJob.FormattedValues["statuscode"]}");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }


    https://learn.microsoft.com/en-us/power-apps/developer/data-platform/auditing/delete-audit-data?tabs=sdk#use-bulkdelete-to-delete-audit-data

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 151 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 134

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 55 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans