Daryl
Daryl

Reputation: 18895

Ignore Duplicate Dection Rules in CRM upon Creation of an Account Within Plugin

I'm attempting to create an account within a Qualification Event Plugin. If I am creating an account with a name that matches exactly a name of an existing account, my Duplicate Detection Rule kicks in, and causes an exception to be thrown.

It was my understanding that duplicate detection rules were always warnings, not errors, and by default, you wouldn't get any errors or even notifications when running from a Plugin/SDK call Is this a new change to CRM? Is there a way to ignore Duplicate Detection Rules from a plugin?

Upvotes: 2

Views: 1239

Answers (2)

James Wood
James Wood

Reputation: 17562

This is intended, and apparently long standing behaviour based on MSDN documentation Run duplicate detection (listed as far back at CRM 2011).

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.

Assuming false is the default as its a bool.

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.

Upvotes: 2

Daryl
Daryl

Reputation: 18895

Apparently you have to set the "SupressDuplicateDetection" Attribute in the create request:

Entity target = new Entity("account");
target["name"] = "I am a clone";
CreateRequest req = new CreateRequest();
req.Target = target;
req["SuppressDuplicateDetection"] = true;
CreateResponse response = (CreateResponse)_service.Execute(req); 

Upvotes: 3

Related Questions