CRM Crate

How to delete an audit history of a specific record in Model-Driven App / Dynamics 365?

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.

How to delete an audit history of a specific record in Model-Driven App / 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 NameProperty Characteristic
ExtensionDataGets 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)
RequestNameGets 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.
Note: The parameter “Target” is referring to a polymorphic lookup field present in the Audit entity.

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”.

Thus, we learned to delete an audit history of a specific record in Model-Driven App / Dynamics 365?

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.