We will learn to delete an audit history of a specific record in Model-Driven App / Dynamics 365. Before we start, make sure to subscribe to CRM Crate so that you can stay up to date in the field of Power Apps / Dynamics 365.
What is an Audit History in Dynamics 365?
The Dynamics 365 CE auditing feature helps to log the changes that are made to customer records and user access so you can review the activity later. The auditing feature is designed to meet the auditing, compliance, security, and governance policies of many regulated enterprises.
Auditing helps the administrative users as given below:
- Who updated this field value on this record and when?
- Who deleted this record?
- Which user was accessing the system and when?
- What was the previous field value before it was updated?
- What actions has this user taken recently?
- What locale was used to make the update?
How to programmatically delete the audit logs for a specific entity record?
We will use the below given Web API Reference Action for dynamically and programmatically delete an audit history for a specific entity record in Dynamics 365.
Understanding DeleteRecordChangeHistory API reference action –
DeleteRecordChangeHistory
Deletes all audit change history records for a particular record.
Required Parameter – Target (The target record to delete the audit)
C++ public ref class DeleteRecordChangeHistoryRequest sealed : Microsoft::Xrm::Sdk::OrganizationRequest
Parameterized Properties –
Property Name | Property Characteristic |
ExtensionData | Gets or sets the structure that contains extra data. Optional. (Inherited from OrganizationRequest) |
Item[String] | Gets or sets the indexer for the Parameters collection.(Inherited from OrganizationRequest) |
Parameters | Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes. (Inherited from OrganizationRequest) |
RequestId | Gets or sets the ID of an asynchronous operation (system job). Optional. (Inherited from OrganizationRequest) |
RequestName | Gets or sets the name of the request. Required, but is supplied by derived classes. (Inherited from OrganizationRequest) |
Target | Gets or sets the target record to delete the audit history for. Required. |
The above given DeleteRecordChangeHistory action deletes the records from “Auditing” entity as per the provided parent target entity GUID.
Invoking DeleteRecordChangeHistory from a Power Automate flow –
- We will call the DeleteRecordChangeHistory API in a Power Automate flow using the dataverse’s “Perform an Unbound Action” connector.
- In our scenario, we will configure the connector to delete the audit logs for a specified Account record.
- Considering an API parameter, we will pass the required target GUID parameter to the OOTB connector as shown below.
Validating the above solutioned audit deletion functionality in Dynamics 365 –
The below example demonstrates the dynamic deletion of Account’s audit logs when the user clicks the ribbon button “Clear Audit History”.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.