Bagikan melalui


DeleteAuditDataRequest Class

 

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

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.

Namespace:   Microsoft.Crm.Sdk.Messages
Assembly:  Microsoft.Crm.Sdk.Proxy (in Microsoft.Crm.Sdk.Proxy.dll)

Inheritance Hierarchy

System.Object
  Microsoft.Xrm.Sdk.OrganizationRequest
    Microsoft.Crm.Sdk.Messages.DeleteAuditDataRequest

Syntax

[DataContractAttribute(Namespace = "https://schemas.microsoft.com/crm/2011/Contracts")]
public sealed class DeleteAuditDataRequest : OrganizationRequest
<DataContractAttribute(Namespace := "https://schemas.microsoft.com/crm/2011/Contracts")>
Public NotInheritable Class DeleteAuditDataRequest
    Inherits OrganizationRequest

Constructors

Name Description
System_CAPS_pubmethod DeleteAuditDataRequest()

Initializes a new instance of the DeleteAuditDataRequest class.

Properties

Name Description
System_CAPS_pubproperty EndDate

Gets or sets the end date and time. Required.

System_CAPS_pubproperty ExtensionData

Gets or sets the structure that contains extra data. Optional.(Inherited from OrganizationRequest.)

System_CAPS_pubproperty Item[String]

Gets or sets the indexer for the Parameters collection.(Inherited from OrganizationRequest.)

System_CAPS_pubproperty Parameters

Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes.(Inherited from OrganizationRequest.)

System_CAPS_pubproperty RequestId

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

System_CAPS_pubproperty RequestName

Gets or sets the name of the request. Required, but is supplied by derived classes.(Inherited from OrganizationRequest.)

Methods

Name Description
System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_pubmethod ToString()

(Inherited from Object.)

Remarks

Message Availability

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

Usage

Pass an instance of this class to the Execute 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.

Examples

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.


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

// Create a delete request with an end date earlier than possible.
DeleteAuditDataRequest 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.
else
{
    for (int n = partitions.Count - 1; n >= 0; --n)
    {
        if (partitions[n].EndDate <= DateTime.Now &amp;&amp; partitions[n].EndDate > deleteRequest.EndDate)
        {
            deleteRequest.EndDate = (DateTime)partitions[n].EndDate;
            break;
        }
    }
}

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

' Get the list of audit partitions.
Dim partitionRequest As RetrieveAuditPartitionListResponse = CType(_service.Execute(New RetrieveAuditPartitionListRequest()), RetrieveAuditPartitionListResponse)
Dim partitions As AuditPartitionDetailCollection = partitionRequest.AuditPartitionDetailCollection

' Create a delete request with an end date earlier than possible.
Dim deleteRequest As New DeleteAuditDataRequest()
deleteRequest.EndDate = New Date(2000, 1, 1)

' Check if partitions are not supported as is the case with SQL Server Standard edition.
If partitions.IsLogicalCollection Then
    ' Delete all audit records created up until now.
    deleteRequest.EndDate = Date.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.
Else
    For n As Integer = partitions.Count - 1 To 0 Step -1
        If partitions(n).EndDate <= Date.Now AndAlso partitions(n).EndDate > deleteRequest.EndDate Then
            deleteRequest.EndDate = CDate(partitions(n).EndDate)
            Exit For
        End If
    Next n
End If

' Delete the audit records.
If deleteRequest.EndDate <> New Date(2000, 1, 1) Then
    _service.Execute(deleteRequest)
    Console.WriteLine("Audit records have been deleted.")
Else
    Console.WriteLine("There were no audit records that could be deleted.")
End If

Thread Safety

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Microsoft.Crm.Sdk.Messages Namespace
Audit entity data changes
Sample: Audit entity data changes

Return to top

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright