Wednesday, January 23, 2019

Cannot insert duplicate key in MS CRM when importing a Solution


A record with these values already exists. A duplicate record cannot be created. Select one or more unique values and try again.

0x80040237  Cannot insert duplicate key.

I got this exception while importing a solution to my QA environment from DEV slot.

Initial Investigation

From the import log, we need to check the sequence whether the error occurred below the “Entity Ribbon” Item Type:


If this is the case, then the most likely cause is duplicate or corrupt CustomControlDefaultConfigs settings.

Solution

1) Identify which entity caused the failure. For example, from the screenshot above we can see the failure comes from the particular entity.

2) Open the solution customizations.xml file and find the problematic entity. Under that entity find the CustomControlDefaultConfigs node and extract the Guid(s) of the default CustomControlDefaultConfigId:



3) Now delete from the source environment this record. This cannot be done via UI unfortunately. So I am using my favorite XrmToolbox to verify and delete the record.


Here is fetchXML to be used 

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="customcontroldefaultconfig">
    <filter type="and">
      <condition attribute="customcontroldefaultconfigid"
                 operator="eq"
                value="{a88b6a06-3f20-e811-9661-00155d00a048}" />
    </filter>
  </entity>
</fetch>

Change the Guid in Fetch xml.

You can use FetchXML Tester to verify if the record exists and after delete again you can run to verify if record got deleted.



To Delete a record we would we would use Bulk Delete Tool






Once record is deleted, try import the same solution again and it should work.

Thanks.
Vipin Jaiswal


No comments: