Duplicate Detection is back in Microsoft Dynamics CRM Spring Release

By | July 8, 2014

How good were the old days of CRM 2011 that even at the point of creation of records you were notified on the entity form itself that the particular record is a duplicate record and hence the data duplication was reduced to a considerable amount. But suddenly in CRM 2013 Duplicate Detection was removed partially i.e., it was no more available on the entity form, at the time of new record creation but it was available on the Home Page of all those entities for which duplicate detection was enabled.

In the Spring Release, Duplicate Detection is back with all its old charm plus a new feature that would be further explained in this blog.

Prior to Spring Release Update if you enabled Duplicate Detection for any of the entity the only way to understand that we have duplicate data in our records was to run Duplicate Detection Job for that entity.

Things have now changed  a bit after the Spring Release update or we can say things have been brought back to normal by reinstating the same old feature of detecting duplicates at the time of Record Creation as well as a new feature that detects duplicate records at Auto Save as well. This reduces the extra steps to some extent that were needed prior to Spring Release update in order to have the Duplicate Detection Job work. However, the same procedure can be followed post the update as well, since it is an essential part for duplicate detection and cannot be removed.

Duplicate Detection on the entity form:

1. At the time of creation of the record:

For this demo, we have created an Account with the name “Apollo.” Now, we are trying to create another Account with same name. So, on the entity form itself we get the Duplicate Detection result. You have the option to Save anyway or Cancel.

Note: Even while creating record using Quick Create Form, you’ll get the Duplicate Detection result there itself.

img1

2.  Auto Save:

Consider you have recently upgraded to Spring Release and you already have duplicate records. You are now updating one of the duplicate records and you mostly rely on Auto Save to save the updates. In that case, you’ll get a notification as shown in the below snapshot:

img2

This is indeed a handy feature that saves our time by detecting duplicate records on the spot and sparing us from going the conventional way.

3. Qualifying Lead:

If you try qualifying a Lead record with the Company Name matching with the existing Account record then in that case you`ll get a Duplicate Warning dialog where you can associate the existing company(Account record) with the current Lead record or else you can Continue creating a new Account record with same name.

img3

Note:  In the above demo we are detecting duplicates by same Account Name. However, it is not simply restricted to Name, you can create your own rules for other fields for other entities as well.

Verifying Duplicate Detection through programming:

While creating a record for an entity programmatically, we observe that even if Duplicate Detection is enabled for the entity, it does not work and it still allows to create the duplicate record for the entity.

In order to enable Duplicate Detection we have to enable “SuppressDuplicateDetection” parameter in the CreateRequest while creating the record for the entity programmatically.

The below code shows how to add this parameter and set its value:

Code Snippet:

Guid id = Guid.Empty;
try
{
//Create an instance of Account entity
Account account = new Account();

//set account name as “Apollo” in order to check Duplicate Detection
//Considering that a record with the name “Apollo” already exists for the Account entity
account.Name = “Apollo“;

// Create operation for creating a new account entity
CreateRequest reqCreate = new CreateRequest();

//Setting the Target of the Request to Account
reqCreate.Target = account;

//This parameter will check for duplication if set to false
reqCreate.Parameters.Add(“SuppressDuplicateDetection“, false);

//Create an instance of CreateResponse to execute the “Create” message
CreateResponse createResponse = (CreateResponse)service.Execute(reqCreate);

//If it is not duplicate then set the newly generated record id to the variable
id = createResponse.id;

}
catch (SaveChangesException ex)
{
throw ex;
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw ex;
}

Note:

If you create records programmatically using CreateRequest with the parameter SuppressDuplicateDetection as false, then duplicate detection will take place and if the record is a duplicate record then it won`t be created and the below error will be shown:

“A record was not created or updated because a duplicate of the current record already exists.”

As you can see, we need the CreateRequest to enable Dup detection while creating record and therefore this feature is not available when creating records using oData.

Duplicate Detection also works while importing records using the OOB import data functionality.

You can also enable duplicate detection and retrieve duplicates programmatically using the RetrieveDuplicatesRequest. An example for the same can be found on MSDN.