Archiving and Deleting Dynamics CRM/CE Audit Logs for Efficient Space Management

26 August 2022
KingswaySoft Team

When auditing is enabled in a CRM/CE/Dataverse entity, it stores the audit details in your instance, i.e., any historical change-related details in the form of audit logs. When this is left unhandled, it can consume space in your instance, and therefore, you might be required to periodically archive audit logs by having them saved to database tables (or any other storage). Once archived, these audit logs may be deleted from the CE/CRM instance, if your business users do not rely on them. This can be done as a manual process from your CRM/CE instance, however, using KingswaySoft, the process can be performed as an automated data flow in SSIS. In this demonstration, we will be looking at how to achieve this. We will be using the below components:

  • Dynamics 365 CRM/CDS Source component
  • Dynamics 365 CRM/CDS Destination component
  • Premium ADO.NET Destination component
  • Premium Derived Column (if required, for any transformations)
  • Data Spawner

The above components can be downloaded as a part of our SSIS Integration Toolkit for Microsoft Dynamics 365 and SSIS Productivity Pack.

Archiving Audit Logs

In order to read and save audit logs, we select the Audit Logs source type in KingswaySoft Dynamics 365 CRM/CDS Source component, as shown below.

Audit logs source type.png

We have a detailed blog post showing how to work with the "Audit Logs" type in the link below:

Now, to save them to a database table, you can use a Premium ADO.NET Destination component. Here you will notice that you have five outputs associated with audits. You can save these into separate database tables, perform a Union All, or a Merge join to save them into one database table.

Audit logs outputs.png

This would be your archival process, where the audit logs are stored for future reference or reporting purposes. After this, comes the process of deletion of those outdated audit log records from the CRM instance, which we will explain in the next section.

Deleting Audit Logs

You could drag and drop a Dynamics 365 CRM Destination component, choose a connection manager, and select the Delete action. Then, search and choose the audit entity as shown below.

Delete Audit CRM Destination component.png

On the Columns page (metadata), you can see that three fields have been discovered:

  • enddate
  • targetid
  • targettype

You have two ways to delete from the audit entity. Either delete all audit recordsuntil a certain date or delete all audit records for a particular record in an entity. Let's see how these methods can work out.

Case 1: Delete historical audit logs by the enddate

If you choose to delete the audits until a certain enddate, then,

    • You would start by using a Data Spawner component, which would generate one row to feed your SSIS pipeline. In the Data Spawner component, you can create a column that would hold a date value, which is the cut-off date for the audit log truncation.
    • As an alternative to using a Data Spawner component to provide the date value, you could also have the value defined in a Premium Derived Column component. Note that both components support using variables as column values should you need to make the process dynamic.
    • As mentioned above, you would then create a Dynamics CRM/CDS destination component that performs a Delete action on the audit entity. The component should be connected to the above Data Spawner or Premium Derived Column component. In the destination component's Columns mapping page, you would simply map the above-mentioned date value column (from either the Data Spawner or Premium Derived Column component) to the enddate field in the destination component.
    • When executed, the data flow should delete all the audit records up until the date specified.
    • While performing this method, the targetid and targettype fields would need to be unmapped.

Delete using enddate.png

Case 2: Delete by targetid

If you chose to delete the audits for certain records, then,

    • Your input can be a list of records instead of one record, as we have explained above using the enddate option.
    • In the columns mappings page, you would need to map the GUID value of the record to the targetid field and the record type to the targetidtype.  This GUID can be obtained using a CDS/CRM Source component or a previously stored record value from any source type.
    • For example, if you want to delete all the audit records for a specific contact, you would map the contactid (GUID) to targetid and map the input that holds the value contact (as a string) or its entity type code (which is 2 for contact) to targetidtype.
    • While performing this method, the enddate would need to be unmapped.

Delete using targetid.png

If you do not have the GUID available, you could possibly leverage the Text Lookup feature available in our CDS/CRM destination component. See the Online Help Manual linked below to learn how to configure and use the text lookup options.

Conclusion

The above can be provided as a chained data flow process by using two different data flow tasks - one for archiving and the other for deleting audit logs - in a timely manner. And as discussed before, the date values can be provided as a variable in our Premium Derived Column component, to have the package pick specific dates in each run. Please do note that the delete action for the audit entity requires an input for either the 'targetid' or 'enddate' field, but not both

We hope this has helped!

Archive

October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags