Hi,
How can I delete MSCRM audit log or audit log history through C# custom code and what user role will be required for doing that?
*This post is locked for comments
Hi,
How can I delete MSCRM audit log or audit log history through C# custom code and what user role will be required for doing that?
*This post is locked for comments
Hi,
bump into this, I was able to execute this function with this.
var DeleteAudit = new DeleteRecordChangeHistoryRequest();
//-- Set entity to delete - workaround as CRM does not allow to delete Audit record directly
DeleteAudit.Target = (EntityReference)record.Attributes["objectid"]; //this is a contact record
if(EntityLogReference.Id != Guid.Empty)
{
_service.Execute(DeleteAudit); //delete all audit history
}
This code runs in a loop of all Audit records and I am filtering it with specific entity w/c is the contact.
Prerequisite reference Microsoft.Crm.Sdk.Proxy (v9.0)
Thanks for your response.
But I want to achieve this through C# custom code using SDK.
Hi,
You can use the Dynamics Workflow Tools utility to delete the record history. There is a new step added recently.
Check this: github.com/.../DeleteRecordAuditHistory.md
Hope this helps.
Hi,
Thanks! Now, I am able to delete bulk records of my last audit partition but it restricts me to delete current or running quarter or partition records.
How can i delete particular records using DeleteRecordChangeHistoryRequest. can you please provide me the C# code using DeleteRecordChangeHistoryRequest?
Hi,
Sample code for quick help,
// 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 && 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.");
Hi,
You can use DeleteAuditDataRequest class and for privileges you can check docs.microsoft.com/.../gg334799%28v%3dcrm.8%29
Thanks,
Ridhima
Hi MSCRM Developer,
You could enable ‘Delete Audit Record Change history’ role to control user delete Audit logs.
[View:https://www.inogic.com/blog/2018/05/deleting-audit-log-in-dynamics-365/amp/]
In addition, there is a DeleteAuditDataRequest in the SDK:
[View:https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg327533(v=crm.8)]
Overall Retrieve and delete the history of audited data changes instruction:
[View:https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/retrieve-and-delete-the-history-of-audited-data-changes]
As I know, you can only delete all audit log records up until a specific date using that request.
Here’s a thread for your reference:
[View:https://community.dynamics.com/crm/f/117/t/236432]
Hope the above could help.
Regards
Johnny
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156