Showing results for 
Search instead for 
Did you mean: 

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)DF1.PNG

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. DF4.PNGThis 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 endsDF2.PNG

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.DF3.PNGIn 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!

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc (
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor