【发布时间】:2020-03-27 14:39:23
【问题描述】:
我想问问有没有办法在两个日期之间删除 Dynamics CRM Online 中的审核日志
【问题讨论】:
标签: c# plugins dynamics-crm dynamics-crm-online
我想问问有没有办法在两个日期之间删除 Dynamics CRM Online 中的审核日志
【问题讨论】:
标签: c# plugins dynamics-crm dynamics-crm-online
删除某个日期范围的更改历史记录
您可以使用 DeleteAuditDataRequest 请求删除某个日期范围的审核记录。审计数据记录从最旧到最新依次删除。根据您的 Common Data Service 服务器使用的 Microsoft SQL Server 版本,此请求的功能略有不同。 Common Data Service 使用企业版 SQL Server。
如果您的 Common Data Service 服务器使用不支持数据库分区功能的 SQL Server 标准版,DeleteAuditDataRequest 请求将删除在 EndDate 属性中指定的结束日期之前创建的所有审核记录。 如果您的 Common Data Service 服务器使用支持分区的企业版 SQL Server,则 DeleteAuditDataRequest 请求将删除那些分区中结束日期早于 EndDate 属性中指定日期的所有审核数据。任何空分区也会被删除。但是,使用此请求或任何其他请求都不能删除当前(活动)分区和该活动分区中的审计记录。
Common Data Service 平台每年按季度自动创建新分区。此功能不可配置且无法更改。您可以使用 RetrieveAuditPartitionListRequest 请求获取分区列表。如果任何分区的结束日期晚于当前日期,则不能删除该分区或其中的任何审计记录。
我们无法在两个日期之间准确删除,但您可以按分区删除审计数据,但要早于某个结束日期。
// 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.
else
{
for (int n = partitions.Count - 1; n >= 0; --n)
{
if (partitions[n].EndDate<DateTime.Now && partitions[n].EndDate>deleteRequest.EndDate)
{
deleteRequest.EndDate=(DateTime)partitions[n].EndDate;
break;
}
}
}
// Delete the audit records.
if (deleteRequest.EndDate != new DateTime(2000, 1, 1))
{
svc.Execute(deleteRequest);
Console.WriteLine("Audit records have been deleted.");
}
else
Console.WriteLine("There were no audit records that could be deleted.");
在 web api 中你可以使用DeleteAuditData Action。
【讨论】: