Answered by:
How to delete duplicate detection rules programatically?

Question
-
Hi All,
Could anyone pls guide me ...how to delete a duplicate detection rule? given its name....
What class or method should i use to achieve this?
Thanks.Tuesday, September 22, 2009 6:18 AM
Answers
-
Hello DeppsMS,
I have put the example code in the following thread..
http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/d348c118-2748-4066-8641-94fcd1931ba7?prof=required
here is pasting the same code from above thread..hope this helps..
CrmService incService = new CrmService(); CrmAuthenticationToken token = new CrmAuthenticationToken(); token.AuthenticationType = 0; token.OrganizationName = <<ORGNAME>>; incService.Url = <<CRM Service URL>> incService.CrmAuthenticationTokenValue = token; // default or network based on your requirement //incService.Credentials = System.Net.CredentialCache.DefaultCredentials; incService.Credentials = new System.Net.NetworkCredential(<<USERNAME>>,<<PASSWORD>>,<<DOMAIN>>); incService.PreAuthenticate = false; incService.UnsafeAuthenticatedConnectionSharing = true; // Create the ColumnSet that indicates the properties to be retrieved. //ColumnSet cols = new ColumnSet(); // Set the properties of the ColumnSet. /cols.co =new AllColumns(); // new string[] { "duplicateruleid" }; // Create the ConditionExpression. ConditionExpression condition = new ConditionExpression(); // Set the condition for the retrieval to be when the contact's address' city is Sammamish. condition.AttributeName = "baseentityname"; condition.Operator =ConditionOperator.In; condition.Values =new string[] { EntityName.opportunity.ToString(), EntityName.account.ToString() , EntityName.contact.ToString() }; // Create the FilterExpression. FilterExpression filterRule = new FilterExpression(); // Set the properties of the filter. filterRule.FilterOperator = LogicalOperator.And; filterRule.Conditions = new ConditionExpression[] { condition }; // Create the QueryExpression object. QueryExpression queryRule = new QueryExpression(); // Set the properties of the QueryExpression object. queryRule.EntityName = EntityName.duplicaterule.ToString(); queryRule.ColumnSet = new AllColumns(); queryRule.Criteria = filterRule; RetrieveMultipleRequest RetRules = new RetrieveMultipleRequest(); RetRules.Query = queryRule; RetrieveMultipleResponse DelRules = (RetrieveMultipleResponse)incService.Execute(RetRules); //if duplicate rules found if (DelRules.BusinessEntityCollection.BusinessEntities.Length > 0) { //MessageBox.Show(DelRules.BusinessEntityCollection.BusinessEntities.Length.ToString()); foreach (BusinessEntity be in DelRules.BusinessEntityCollection.BusinessEntities) { duplicaterule myCrmObject = (duplicaterule)be; TargetDeleteDuplicateRule deleteRule = new TargetDeleteDuplicateRule(); deleteRule.EntityId = myCrmObject.duplicateruleid.Value; DeleteRequest deleteRequest = new DeleteRequest(); deleteRequest.Target = deleteRule; DeleteResponse deleted = (DeleteResponse)incService.Execute(deleteRequest); } }
- Proposed as answer by Mayank PujaraEditor Sunday, October 11, 2009 12:03 PM
- Marked as answer by Donna EdwardsMVP Tuesday, October 13, 2009 7:54 PM
Sunday, October 11, 2009 12:02 PMAnswerer
All replies
-
Try using TargetDeleteDuplicateRule Class (CrmService). and DeleteRequest class. Its 3 in the night so I would try to provide some sample code in my next post.
- Proposed as answer by Santosh Kore Sunday, October 11, 2009 5:08 PM
Sunday, October 11, 2009 7:52 AM -
Hello DeppsMS,
I have put the example code in the following thread..
http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/d348c118-2748-4066-8641-94fcd1931ba7?prof=required
here is pasting the same code from above thread..hope this helps..
CrmService incService = new CrmService(); CrmAuthenticationToken token = new CrmAuthenticationToken(); token.AuthenticationType = 0; token.OrganizationName = <<ORGNAME>>; incService.Url = <<CRM Service URL>> incService.CrmAuthenticationTokenValue = token; // default or network based on your requirement //incService.Credentials = System.Net.CredentialCache.DefaultCredentials; incService.Credentials = new System.Net.NetworkCredential(<<USERNAME>>,<<PASSWORD>>,<<DOMAIN>>); incService.PreAuthenticate = false; incService.UnsafeAuthenticatedConnectionSharing = true; // Create the ColumnSet that indicates the properties to be retrieved. //ColumnSet cols = new ColumnSet(); // Set the properties of the ColumnSet. /cols.co =new AllColumns(); // new string[] { "duplicateruleid" }; // Create the ConditionExpression. ConditionExpression condition = new ConditionExpression(); // Set the condition for the retrieval to be when the contact's address' city is Sammamish. condition.AttributeName = "baseentityname"; condition.Operator =ConditionOperator.In; condition.Values =new string[] { EntityName.opportunity.ToString(), EntityName.account.ToString() , EntityName.contact.ToString() }; // Create the FilterExpression. FilterExpression filterRule = new FilterExpression(); // Set the properties of the filter. filterRule.FilterOperator = LogicalOperator.And; filterRule.Conditions = new ConditionExpression[] { condition }; // Create the QueryExpression object. QueryExpression queryRule = new QueryExpression(); // Set the properties of the QueryExpression object. queryRule.EntityName = EntityName.duplicaterule.ToString(); queryRule.ColumnSet = new AllColumns(); queryRule.Criteria = filterRule; RetrieveMultipleRequest RetRules = new RetrieveMultipleRequest(); RetRules.Query = queryRule; RetrieveMultipleResponse DelRules = (RetrieveMultipleResponse)incService.Execute(RetRules); //if duplicate rules found if (DelRules.BusinessEntityCollection.BusinessEntities.Length > 0) { //MessageBox.Show(DelRules.BusinessEntityCollection.BusinessEntities.Length.ToString()); foreach (BusinessEntity be in DelRules.BusinessEntityCollection.BusinessEntities) { duplicaterule myCrmObject = (duplicaterule)be; TargetDeleteDuplicateRule deleteRule = new TargetDeleteDuplicateRule(); deleteRule.EntityId = myCrmObject.duplicateruleid.Value; DeleteRequest deleteRequest = new DeleteRequest(); deleteRequest.Target = deleteRule; DeleteResponse deleted = (DeleteResponse)incService.Execute(deleteRequest); } }
- Proposed as answer by Mayank PujaraEditor Sunday, October 11, 2009 12:03 PM
- Marked as answer by Donna EdwardsMVP Tuesday, October 13, 2009 7:54 PM
Sunday, October 11, 2009 12:02 PMAnswerer -
Ahhaaaa there you go MayankP .Sunday, October 11, 2009 5:08 PM