Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Run Duplicate Detection

[Applies to: Microsoft Dynamics CRM 2011]

There are several ways to perform duplicate detection after you enable it and publish the duplicate detection rules:

 

Action Description

Detect duplicates for a specified record

Use the RetrieveDuplicatesRequest message. For example, you can use this message to find all the contacts that are duplicates of a particular account record.

Detect duplicates for an entity type

Use the BulkDetectDuplicatesRequest message. This message submits an asynchronous duplicate detection job that runs in the background. The BulkDetectDuplicates message is used to find the duplicate records for a specified entity type based on the query expression passed in this message request. The duplicates are detected according to the published duplicate rules for the entity type. The detected duplicates are stored as duplicate record (DuplicateRecord) records in Microsoft Dynamics CRM. You can retrieve duplicate records by using the Retrieve method or the RetrieveMultiple method.

A maximum of 5000 duplicates are returned by the duplicate detection job.

Detect duplicates during Create and Update operations

Pass the duplicate detection optional parameter SuppressDuplicateDetection by adding a value to the Parameters property of the CreateRequest and UpdateRequest message requests. The SuppressDuplicateDetection parameter value determines whether the Create or Update operation can be completed:

  • true – Create or update the record, if a duplicate is found.

  • false - Do not create or update the record, if a duplicate is found.

noteNote
Passing of the CalculateMatchCodeSynchronously optional parameter is no longer required. The match codes used to detect duplicates are calculated synchronously regardless of the value passed in this parameter.

noteNote
If the duplicate detection optional parameter is set to false and a duplicate is found, an exception is thrown and the record is not created or updated.

The following example shows how to pass the duplicate detection option as a part of the CreateRequest and UpdateRequest message requests:


// Connect to the Organization service. 
// The using statement assures that the service proxy will be properly disposed.
using (_serviceProxy = ServerConnection.GetOrganizationProxy(serverConfig))
{
    // This statement is required to enable early-bound type support.
    _serviceProxy.EnableProxyTypes();

    _service = (IOrganizationService)_serviceProxy;

    CreateRequiredRecords();

    // Create and account record with the named Proseware, Inc. and already existing Account Number.
    Account account = new Account 
    {
        Name = "Proseware, Inc.",
        AccountNumber = "ACC005"
    };

    // Create operation by suppressing duplicate detection
    CreateRequest reqCreate = new CreateRequest();
    reqCreate.Target = account;
    reqCreate.Parameters.Add("SuppressDuplicateDetection", true); // Change to false to activate the duplicate detection.
    CreateResponse createResponse = (CreateResponse)_service.Execute(reqCreate);
    _dupAccountId = createResponse.id;
    Console.Write("Account: {0} {1} created with SuppressDuplicateDetection to true, ", 
        account.Name, account.AccountNumber);
    
    // Retrieve the account containing with its few attributes.
    ColumnSet cols = new ColumnSet(
        new String[] { "name", "accountnumber"});

    Account retrievedAccount = (Account)_service.Retrieve("account", _dupAccountId, cols);
    Console.Write("retrieved, ");

    // Update the existing account with new account number.
    retrievedAccount.AccountNumber = "ACC006";                   

    // Update operation – update record, if a duplicate is not found.
    UpdateRequest reqUpdate = new UpdateRequest();
    reqUpdate.Target = retrievedAccount;
    reqUpdate["SuppressDuplicateDetection"] = false; // Duplicate detection is activated.

    // Update the account record.
    UpdateResponse updateResponse = (UpdateResponse)_service.Execute(reqUpdate);
    Console.WriteLine("and updated.");

    DeleteRequiredRecords(promptforDelete);
}

See Also

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.