DeleteAuditDataRequest DeleteAuditDataRequest DeleteAuditDataRequest DeleteAuditDataRequest Class


Contains the data that is needed to delete all audit data records up until a specified end date.

For the Web API use the DeleteAuditData Action.

public ref class DeleteAuditDataRequest sealed : Microsoft::Xrm::Sdk::OrganizationRequest
public sealed class DeleteAuditDataRequest : Microsoft.Xrm.Sdk.OrganizationRequest
type DeleteAuditDataRequest = class
    inherit OrganizationRequest
Public NotInheritable Class DeleteAuditDataRequest
Inherits OrganizationRequest


// Get the list of audit partitions.
          var partitionRequest =(RetrieveAuditPartitionListResponse)svc.Execute(new RetrieveAuditPartitionListRequest());
            AuditPartitionDetailCollection partitions = partitionRequest.AuditPartitionDetailCollection;

// Create a delete request with an end date earlier than possible.
         var deleteRequest = new DeleteAuditDataRequest();
             deleteRequest.EndDate = new DateTime(2000, 1, 1);

// Check if partitions are not supported as is the case with SQL Server Standard edition.
if (partitions.IsLogicalCollection)
    // Delete all audit records created up until now.
    deleteRequest.EndDate = DateTime.Now;

// Otherwise, delete all partitions that are older than the current partition.
// Hint: The partitions in the collection are returned in sorted order where the 
// partition with the oldest end date is at index 0.
    for (int n = partitions.Count - 1; n >= 0; --n)
        if (partitions[n].EndDate<DateTime.Now && partitions[n].EndDate>deleteRequest.EndDate)

// Delete the audit records.
    if (deleteRequest.EndDate != new DateTime(2000, 1, 1))
        Console.WriteLine("Audit records have been deleted.");
    Console.WriteLine("There were no audit records that could be deleted.");

The following example shows how to use this message. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface. For the complete sample, see the link later in this topic.




Message Availability

For this message to work, the caller must be connected to the server.


Pass an instance of this class to the Execute(OrganizationRequest) method, which will return an instance of DeleteAuditDataResponse.

Privileges and Access Rights

For a list of the privileges required, see DeleteAuditData message privileges.

Notes for Callers

This message behaves slightly different depending on the version of Microsoft SQL Server that is installed on the Microsoft Dynamics 365 server. See Retrieve and delete the history of audited data changes for more information.


DeleteAuditDataRequest() DeleteAuditDataRequest() DeleteAuditDataRequest() DeleteAuditDataRequest()

Initializes a new instance of the DeleteAuditDataRequest class.


EndDate EndDate EndDate EndDate

Gets or sets the end date and time. Required.

ExtensionData ExtensionData ExtensionData ExtensionData

Gets or sets the structure that contains extra data. Optional.

(Inherited from OrganizationRequest)
Item[String] Item[String] Item[String] Item[String]

Gets or sets the indexer for the Parameters collection.

(Inherited from OrganizationRequest)
Parameters Parameters Parameters Parameters

Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
RequestId RequestId RequestId RequestId

Gets or sets the ID of an asynchronous operation (system job). Optional.

(Inherited from OrganizationRequest)
RequestName RequestName RequestName RequestName

Gets or sets the name of the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)

Applies to