Delete duplicate records/ items from Dynamics 365 CRM/ CDS/ SharePoint
In this post, I will show you how to detect duplicate records/ items in Dynamics 365 CRM/ CDS/ SharePoint, delete the record/ item and send a list of deleted records/ items as an email attachment. We will look at finding duplicate entries based on specific fields/ columns (specific values on these fields/ columns), deleting those and sending an email with the list of deleted records/ items.
Let’s get started with the Flow
Trigger: Manual Button
Action: Initialize an array variable: This will accommodate the unique identifier to look for in the duplicate records.
Action: Initialize an array variable 2: This will accommodate all the deleted items to be added to the List that will be sent as an email attachment.
Action: List Records (For Dynamics and CDS); Get Items (For SharePoint)
Note: in the List Records action, we are trying to fetch as many as 10000 records and iterate over them. To get duplicates of a particular value on a field/ column, the ODATA filter query can be modified to get filtered records/ items only. This will only fetch records where the 'crceb_name' field equals "Yash". In the ODATA filter query, to filter on a particular field, the logical name of the attribute needs to be used for the filter query.
Control: Apply to each (to iterate over each record/item retrieved in the previous step).
//Loop starts
Control: Condition: To check if Array 1 contains the value for the field/column on which a duplicate entry is to be identified.
If Array 1 contains the value,
Action: Append to Array Variable 2: append the current item of the loop to the Array 2
Action: Delete a record (for Dynamics and CDS); Delete Item (for SharePoint): To delete the current item.
If Array 1 does not contain the value,
Action: Append to Array Variable 1: append the unique identifier field to Array 1 (this will be used to populate the unique values for the particular field/ column on which the duplicate entries are to be checked)
//Loop ends
Action: Create an HTML table: to create a table of the deleted records/ items.
Action: Send an Email: to send an email with the list of deleted items as an attachment.In this post, I have shown you how to identify and delete duplicate records/ items from Dynamics 365 CRM/ CDS/ SharePoint based on a particular field/ column. The same logic flow can be applied for any other data sources with minor tweaks. This flow is a manually triggered one for data that is already present in the respective data-sources. A schedule trigger can be used in this flow to run it on a daily basis and the ODATA query in the List Records/ Get Items action can be modified to get records created during the past 24 hours only and check if any duplicate entries have been made in the last 24 hours (however, to check the duplicate entries with data older than the last 24 hours, the original flow can be used).
I hope you found this interesting and it helped you. Thank you for reading!
Comments
-
Delete duplicate records/ items from Dynamics 365 CRM/ CDS/ SharePoint
More efficient way to get & remove duplicates here: https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Find-and-Remove-Duplicates/m-p/2191403#M1611
*This post is locked for comments