Sometimes you may require to retrieve duplicate detection rules using CRM SDK. This post will help you to write code to get duplicate detection rule. Let’s take an example, we want to retrieve all the duplicate detection rules based on the entity name. If you will navigate to Settings-> Data Management -> Duplicate Detection Rules, you will see duplicate detection rules for entities. For example, below is the duplicate rules for contact entity.
- using(OrganizationService crmService = new OrganizationService("OrganizationService"))
- {
- QueryExpression query = new QueryExpression
- {
- EntityName = "duplicaterule",
- ColumnSet = new ColumnSet("name"),
- Criteria = {
- FilterOperator = LogicalOperator.And,
- Conditions = {
- new ConditionExpression
- {
- AttributeName = "baseentityname",
- Operator = ConditionOperator.Equal,
- Values = {
- "contact"
- }
- },
- new ConditionExpression
- {
- AttributeName = "statecode",
- Operator = ConditionOperator.Equal,
- Values = {
- 1
- }
- }
- }
- }
- };
- }
- EntityCollection entityCollection = crmService.RetrieveMultiple(query);
After that we can loop through entity collection to get individual duplicate rule if required using the following code:
- foreach (Entity duplicaterule in entityCollection.Entities)
- {
- //processing entitycollection records
- }
- new ConditionExpression
- {
- AttributeName="statecode",
- Operator=ConditionOperator.Equal,
- Values={0}
- }

Santhakumar MunuswamyPosted Oct 25, 2015, 11:39 AM
Good one
Nilesh JadavPosted Oct 23, 2015, 8:17 AM
Good share!!
Sibeesh VenuPosted Oct 23, 2015, 1:35 AM
Nice Share
Harshad PansuriyaPosted Oct 23, 2015, 12:01 AM
Nice one
Mukesh KumarPosted Oct 22, 2015, 2:45 PM
Good Job Sir