How to identify duplicate records with a plugin in Dynamics CRM 2011

亡梦爱人 提交于 2019-12-06 15:39:39

You can use the RetrieveDuplicatesRequest as per this example here:

    /// <summary>
    /// Checks for duplicate Guid
    /// </summary>
    /// <param name="account"></param>
    /// <returns>First duplicate account id, if any duplicates found, and Guid.Empty if not</returns>
    public Guid DuplicateExists(Account account)
    {
        RetrieveDuplicatesRequest request = new RetrieveDuplicatesRequest();
        request.BusinessEntity = account;
        request.MatchingEntityName = Account.EntityLogicalName;
        request.PagingInfo = new PagingInfo();
        request.PagingInfo.PageNumber = 1;
        request.PagingInfo.Count = 1;

        RetrieveDuplicatesResponse response = (RetrieveDuplicatesResponse)ServiceProxy.Execute(request);
        return response.DuplicateCollection.Entities.Count > 0 ? response.DuplicateCollection.Entities[0].Id : Guid.Empty;
    }

See http://crm-edinburgh.com/2011/08/crm-sdk-using-detect-duplicates-settings-in-code/ for an example.

Are you aware of the built-in duplicate detection?

See following links:

although the links describe the duplicate detection of Dynamics CRM 4, they are still valid for Dynamics CRM 2011

Take a look at the article Run Duplicate Detection in the Dynamics CRM 2011 SDK.

You could either use the optional parameter SuppressDuplicateDetection or you could use the RetrieveDuplicatesRequest, although this will only work for existing records.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!