Performing BulkDelete Action in Microsoft Dynamics 365 CRM

14 July 2020
Aswin Manmadhan

Microsoft Dynamics 365 CRM Bulk delete action is provided by the API to submit a bulk delete job that deletes selected records in bulk. This job is asynchronous and runs in the background without blocking other activities. The bulk delete action doesn’t necessarily make delete action faster, but given it runs in the background, it’s advantageous in comparison to the regular delete action.

The BulkDelete action requires a FetchXML to query the records targeted for deletion. This query can be a string in the “BulkDeleteQuery” field of our CRM Destination component. The recommended approach to do this would be by using a Derived Column component. Before we proceed with our example, let’s take a look at what are the fields that are exposed (both required and optional) for BulkDelete action.

  • BulkDeleteQuery: the FetchXML query for a bulk delete job.
  • CCRecipients: the GUID id of the systemuser listed in the CC box of the email notification.
  • JobName: the name of the bulk delete job.
  • SendEmailNotification: a boolean value that indicates whether to send an email notification after the bulk delete job has finished running.
  • ToRecipients: the GUID id of the systemuser listed in the To box of the email notification.
  • RecurrencePattern: Sets the recurrence pattern for the bulk delete job. (Optional)
  • StartDateTime:   Sets the start date and time to run a bulk delete job. (Optional)

To build a FetchXML query, use our CRM Source component within our SSIS Integration Toolkit for Microsoft Dynamics 365. It has an inbuilt SQL-to-FetchXML converter where you enter your SQL query to get the appropriate FetchXML.

CDS/CRM Source Component Editor

Convert a SQL Query to a FetchXML Statement

Please note that the CRM Source component here is just for building the FetchXML query, and it is not used in the data flow. You can remove it once you get the query. In our example, we are going to use BulkDelete action to delete accounts that were created before a specific date (in our case, October 10, 2018).

<fetch mapping="logical" version="1.0">
  <entity name="account">
    <all-attributes />
    <filter>
      <condition attribute="createdon" operator="lt" value="2018-10-10" />
    </filter>
  </entity>
</fetch>

We can now enter this FetchXML query in our Premium Derived Column component. Since the Premium Derived Column component is a transformation component, a source component is required in the upstream. Our Data Spawner component can be used for this (both our Premium Derived Column and Data Spawner components can be found in our SSIS Productivity Pack). You can follow the below design.

FetchXML in our Premium Derived Column Component

As you can see, the FetchXML query would need to be appropriately escaped and tested to be in the correct format. You can give the other required fields in it as well. Please note that a variable or a parameter can be used inside the FetchXML query to parameterize it so that it can dynamically accept values at runtime. This would be useful when the filter condition (createdon field, in this case) needs to be dynamically passed. You would be able to concatenate variables properly using the Premium Derived column expression editor.

Test Results

The “JobName” can be any distinguishable name used to identify the job and its nature. And the “RecurrencePattern” is optional, and is used to specify if the job needs to be recurring. Microsoft allows the below parameters in the BulkDelete jobs.

Microsoft Approved Recurrence Pattern

There could be restrictions as to what frequency can be set. You should check the below link for more details.

Once you have provided these, you can map them to the CRM Destination component, by choosing the “BulkDelete” action in it.

CDS/CRM Source Component Editor - Bulk Delete Action

CDS/CRM Source Component Editor - Columns

Now, as BulkDelete jobs are asynchronous, your data flow task should execute successfully and complete in some time, as long as you there are no other logical errors. The BulkDelete job runs in the background, and you would be able to see the job going through its phases from your CRM UI by navigating to Settings > Data Management > Bulk Record Deletion.

Data Flow Task

Bulk Record Deletion

My Bulk Deletion System Jobs

Final Thought

In this way, using BulkDelete action, you can quickly delete numerous records in CRM at a go as a background process. Please note that you can have another data source to provide the FetchXML query and other fields, and using our Data Spawner is just one possibility.

Archive

November 2024 3 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