web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Duplicate Detection and Merging using C#, CRM SDK

(0) ShareShare
ReportReport
Posted on by 480

Hi Everyone,

I am trying to create a utility (windows app) which will detect duplicates based on an existing "Duplicate Detection Rule" in Dynamics CRM and then will merge the records based on most recent record (modified on) found.

I am able to get the duplicates programmatically but I don't know how to identify the duplicate pairs i.e. which one is duplicate of which record.

My Present Code Looks Like This:-

BulkDetectDuplicatesRequest request = new BulkDetectDuplicatesRequest()
            {
                JobName = "Accounts with same Address",
                Query = new QueryExpression()
                {
                    EntityName = "account",
                    ColumnSet = new ColumnSet(true)
                },
                RecurrencePattern = String.Empty,
                RecurrenceStartTime = DateTime.Now,
                ToRecipients = new Guid[0],
                CCRecipients = new Guid[0]
            };

            BulkDetectDuplicatesResponse _response = (BulkDetectDuplicatesResponse)service.Execute(request);

            //Guid jobid = Guid.Parse("8549a21f-5b74-e811-8159-e0071b67aca1");

            WaitForAsyncJobToFinish(_response.JobId, 150);


            QueryByAttribute query = new QueryByAttribute()
            {
                ColumnSet = new ColumnSet(true),
                EntityName = "duplicaterecord"
            };
            query.Attributes.Add("asyncoperationid");
            query.Values.Add(_response.JobId);
            //retrieve all the duplicates found by the system Job
            EntityCollection results = service.RetrieveMultiple(query);

Any Suggestions?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Rizwan,

    Once you got all the duplicate records, you need to iterate through each one and then again find the duplicates of that record using RetrieveDuplicate message. Once you find the duplicate of that record, iterate again and merge it with the main record.

    Do remember to check for for status = active for each record as the records may merge with other records during the complete process.

    Hope this helps.

  • Rizwan Aarif Profile Picture
    480 on at

    As suggested by you, I am looping through each record found in "results" and executing a RetrieveDuplicateRequest but I am getting "Duplicate detection is not supported on this record type.'" error. I am using this for Account entity.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    This is strange. I have built this utility in past using the same concept. You sure duplicate detection is enabled for Account. The message retrieveDuplicate is supported for Account entity. Check below-

    msdn.microsoft.com/.../gg328244.aspx

    Hope this helps.

  • Rizwan Aarif Profile Picture
    480 on at

    Hi Ravi,

    Sorry, I was running it on "DuplicateRecord" by mistake. I corrected it and ran on "baserecordid" (an entity reference) and it worked fine.

    Thank you for the help :)

  • Jag S Profile Picture
    214 on at

    Hi All,

    Can we merge custom entities as well. We have participants registering for multiple studies , which creates duplicates and then only element different is the study name.

    I like to merge the duplicates into one contact but retain which studies the contact registered.

    I'm new to dynamics crm and any help would be highly appreciated.

    Thanks

    Jag

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans