CRM 2016 SP1 (onPrem) / Upgrade from 2011 - Solution Imports Error "Cannot insert duplicate key"

Question Status

Suggested Answer
Matthias Back asked a question on 2 Aug 2016 2:11 PM

Hi

I had an CRM 2016 SP1 (onPrem) enviroment, which was upgraded from 2011.

After fixing some ribbon dependency problems, I still have the Problem that my customizing solution with 2 entities could not be imported on the target system. The solution is an full export.  Import results with the following error:

21:07:24.44     cu_basketlineitem       Failure 0x80040237 Cannot insert duplicate key.

After checking the extracted Solution XML I was wondering what the section

<CustomControlDefaultConfigs>

<CustomControlDefaultConfig>

<PrimaryEntityTypeCode>10133</PrimaryEntityTypeCode>

<CustomControlDefaultConfigId>{c20790db-883f-e611-80d8-3ca82a15e5e7}</CustomControlDefaultConfigId>

<ControlDescriptionXML>

<controlDescriptions />

</ControlDescriptionXML>

<IntroducedVersion>1.0</IntroducedVersion>

</CustomControlDefaultConfig>

</CustomControlDefaultConfigs>

When I remove that section: the solution could imported without any Problems! How could I handle that this will not be exported automatically?

Regards

Matthias

Reply
Matthias Back responded on 4 Aug 2016 12:13 PM

has nobody an idea?

Reply
Pablo Peralta, MVP responded on 7 Sep 2016 9:05 AM

same problem here. thanks for  pointing out to this workaround.

Just to clarify / share what really worked for me was not removing that node but removing its content. So, just leave it <CustomControlDefaultConfigs></CustomControlDefaultConfigs>

Thanks.

PP

Reply
Suggested Answer
Pablo Peralta, MVP responded on 21 Sep 2016 1:18 PM

If still doesn't work, try this:

select * from CustomControlDefaultConfigBase where PrimaryEntityTypeCode not in (select objecttypecode from entity)

after that:

DELETE from CustomControlDefaultConfigBase where PrimaryEntityTypeCode in (object type codes resulted from prev query separated by commas)

this was after dealing this issue with MS support. Fix is supposed to be released with update 1 for 2016 sp1, late oct 2016.

If CRM Online, call and ask Microsoft to do this for you.

It seems an issue after deleting some entity, but customcontrols are not deleted automatically.

hope it helps to somebody else.

thanks

PP

Reply
pbohdan responded on 18 Oct 2016 3:40 AM

.

Reply
Kevin Bowman responded on 15 Nov 2016 1:30 PM

I have the same issue here, deploying a custom entity in an unmanaged solution to a brand new CRM Org.

How did you come to decide which one to remove, and what is the impact of removing it ?

Thanks

Kevin.

Reply
Runner288s responded on 15 Nov 2016 1:41 PM

Good question. It is not supposed to modify the solution file unless you clearly understand it. Otherwise, it may be uncertain on the result.

File a Microsoft ticket.

Thanks

Runner288

Reply
Suggested Answer
Kevin Bowman responded on 16 Nov 2016 8:53 AM

So I reached out to Microsoft Support as I was having a similar issue with 2 of my custom entities, after I applied a similar hack.

They say at this point that "the workaround will not be different from the one that we can provide and we will not expect any negative impact but let me route this case to a colleague".  I'll keep you updated on what they confirm from the Dev Team.

Reply
Mili responded on 23 Nov 2016 12:33 AM

Any latest update Kevin? I had been facing same issue.  I hope MS will provide fix in their next release

Reply
Suggested Answer
Hans van Toorn responded on 24 Nov 2016 4:04 AM

Hi had also this issue, and fixed it with the following queries:

I used this query to identify the duplicate keys, and the checked in the customizations.xml which value was incorrect, and which was correct

 

with lst as (

select CustomControlDefaultConfigId, count(*) cnt

from CustomControlDefaultConfig

group by CustomControlDefaultConfigId

having count(*) > 1

)

select ent.name, lst.CustomControlDefaultConfigId, cfg.CustomControlDefaultConfigIdUnique,   cfg.*

from lst

inner join CustomControlDefaultConfig cfg on cfg.CustomControlDefaultConfigId = lst.CustomControlDefaultConfigId

left join entity ent on ent.ObjectTypeCode = cfg.PrimaryEntityTypeCode

 

I then used this query to replace the incorrect duplicate key with the CustomControlDefaultConfigIdUnique

 

update CustomControlDefaultConfig

set CustomControlDefaultConfigId = CustomControlDefaultConfigIdUnique

where CustomControlDefaultConfigIdUnique = 'the wrong CustomControlDefaultConfigIdUnique'

Reply
bigly responded on 2 Dec 2016 9:09 AM

Thanks for the useful query Hans.

For us the best/permanent resolution was somewhere between Hans's and Pablo's...

  • Find the entities that are clashing and identify which entity is 'bad'

(Using Han's query and/or by searching customizations.xml for the entity type code with multiple CustomControlDefaultConfig nodes)

  • delete from CustomControlDefaultConfigBase where PrimaryEntityTypeCode = <BAD ENTITY TYPE CODE> AND CustomControlDefaultConfigId = '<DUPLICATED ID>'
  • Export the solution again

If you modify the solution file obviously it doesn't stop the same thing happening the next time you export from the source Org.

If you update the duplicate row, you still have 2 rows against the custom entity which isn't the state the DB would be in if you didn't have the problem in the first place. Also, it doesn't seem like any CustomControlDefaultConfig row typically has the same ID in the CustomControlDefaultConfigId as CustomControlDefaultConfigIdUnique so rather than leaving behind a row in an unusual state, we just deleted it (and only it).

Reply
pbohdan responded on 2 Dec 2016 9:28 AM

We've founded three types of errors

1. One entity has two CustomControlDefaultConfigs

Like that

We tried to delete one of the duplicated CustomControlDefaultConfig (randomly). Seems it works.

2. Two entities have the same CustomControlDefaultConfigid

Like that

What to do with that? Deleting one of the duplicated CustomControlDefaultConfig crashes the system (impossible to export default solution)

3. Entity with unique  CustomControlDefaultConfigid, but solution import crashes with error customcontroldefaultconfig With Id = d3226572-022c-e611-80e6-00155dc26410 Does Not Exist. The solution contains only one CustomControlDefaultConfig for this entity

     <CustomControlDefaultConfigs>

        <CustomControlDefaultConfig>

          <PrimaryEntityTypeCode>10084</PrimaryEntityTypeCode>

          <CustomControlDefaultConfigId>{bd771d8c-2cd6-e511-80d4-00155d0e4417}</CustomControlDefaultConfigId>

          <ControlDescriptionXML>

            <controlDescriptions />

          </ControlDescriptionXML>

          <IntroducedVersion>1.0</IntroducedVersion>

        </CustomControlDefaultConfig>

      </CustomControlDefaultConfigs>

 

No idea yet.

Reply
Natraj Yegnaraman responded on 9 Jan 2017 3:50 PM

This should no longer happen in Dynamics 365 Online, as it has been fixed in Service Update 5 -> support.microsoft.com/.../3216919

Hopefully this fix makes it way to OnPrem soon.

Reply
Cleiton Santos responded on 28 Jan 2017 11:04 AM

Hi guys,

I have SP1 on my on-prem CRM and I tried all solutions mentioned above but no dice. Any ideas?

*************

Couldn’t import a Custom Control Default Config for ObjectTypeCode 10037 because its 'customcontroldefaultconfigid' already exists on the system.

Reply
Cleiton Santos responded on 28 Jan 2017 12:34 PM

Hey  did you find a solution for the issue? I have similar situation here like #1 on your comments

pbohdan

We've founded three types of errors

1. One entity has two CustomControlDefaultConfigs

Like that

We tried to delete one of the duplicated CustomControlDefaultConfig (randomly). Seems it works.

2. Two entities have the same CustomControlDefaultConfigid

Like that

What to do with that? Deleting one of the duplicated CustomControlDefaultConfig crashes the system (impossible to export default solution)

3. Entity with unique  CustomControlDefaultConfigid, but solution import crashes with error customcontroldefaultconfig With Id = d3226572-022c-e611-80e6-00155dc26410 Does Not Exist. The solution contains only one CustomControlDefaultConfig for this entity

     <CustomControlDefaultConfigs>

        <CustomControlDefaultConfig>

          <PrimaryEntityTypeCode>10084</PrimaryEntityTypeCode>

          <CustomControlDefaultConfigId>{bd771d8c-2cd6-e511-80d4-00155d0e4417}</CustomControlDefaultConfigId>

          <ControlDescriptionXML>

            <controlDescriptions />

          </ControlDescriptionXML>

          <IntroducedVersion>1.0</IntroducedVersion>

        </CustomControlDefaultConfig>

      </CustomControlDefaultConfigs>

 

No idea yet.

Reply
Suggested Answer
Cleiton Santos responded on 29 Jan 2017 10:24 AM

Hi all.

I believe I found out the issue I was having. Basically I had the same #1 situation as  , however deleting randomly didn't solve the issue. The right thing to do is not delete randomly but the oldest record.

I believe it is related to entity recreation because we had to recreate some entities changing the Ownership type to Organization instead of User or Team and this may have generated the issue. I also checked on other project implementation that the other team decided to start a brand new org instead of finding a solution for the issue and they had the same duplication (it was even worst because they had several duplicated records) and it worked like charm.

That being said try to apply the steps below to fix the issue:

  1. Use the script below to find the oldest duplicated records on CustomControlDefaultConfigBase

    select
    PrimaryEntityTypeCode,
    min(CreatedOn) oldest
    from
    CustomControlDefaultConfigBase
    where
    PrimaryEntityTypeCode in (select
    PrimaryEntityTypeCode
    from
    CustomControlDefaultConfigBase
    group by
    PrimaryEntityTypeCode
    having
    count(1) >1)
    group by
    PrimaryEntityTypeCode

  2. Delete these records and export the solution again (managed or unmanaged)
  3. Try to import it on the new environment

Thanks for the tips

Reply
Suggested Answer
Pablo Peralta, MVP responded on 21 Sep 2016 1:18 PM

If still doesn't work, try this:

select * from CustomControlDefaultConfigBase where PrimaryEntityTypeCode not in (select objecttypecode from entity)

after that:

DELETE from CustomControlDefaultConfigBase where PrimaryEntityTypeCode in (object type codes resulted from prev query separated by commas)

this was after dealing this issue with MS support. Fix is supposed to be released with update 1 for 2016 sp1, late oct 2016.

If CRM Online, call and ask Microsoft to do this for you.

It seems an issue after deleting some entity, but customcontrols are not deleted automatically.

hope it helps to somebody else.

thanks

PP

Reply
Suggested Answer
Kevin Bowman responded on 16 Nov 2016 8:53 AM

So I reached out to Microsoft Support as I was having a similar issue with 2 of my custom entities, after I applied a similar hack.

They say at this point that "the workaround will not be different from the one that we can provide and we will not expect any negative impact but let me route this case to a colleague".  I'll keep you updated on what they confirm from the Dev Team.

Reply
Suggested Answer
Hans van Toorn responded on 24 Nov 2016 4:04 AM

Hi had also this issue, and fixed it with the following queries:

I used this query to identify the duplicate keys, and the checked in the customizations.xml which value was incorrect, and which was correct

 

with lst as (

select CustomControlDefaultConfigId, count(*) cnt

from CustomControlDefaultConfig

group by CustomControlDefaultConfigId

having count(*) > 1

)

select ent.name, lst.CustomControlDefaultConfigId, cfg.CustomControlDefaultConfigIdUnique,   cfg.*

from lst

inner join CustomControlDefaultConfig cfg on cfg.CustomControlDefaultConfigId = lst.CustomControlDefaultConfigId

left join entity ent on ent.ObjectTypeCode = cfg.PrimaryEntityTypeCode

 

I then used this query to replace the incorrect duplicate key with the CustomControlDefaultConfigIdUnique

 

update CustomControlDefaultConfig

set CustomControlDefaultConfigId = CustomControlDefaultConfigIdUnique

where CustomControlDefaultConfigIdUnique = 'the wrong CustomControlDefaultConfigIdUnique'

Reply
Suggested Answer
Cleiton Santos responded on 29 Jan 2017 10:24 AM

Hi all.

I believe I found out the issue I was having. Basically I had the same #1 situation as  , however deleting randomly didn't solve the issue. The right thing to do is not delete randomly but the oldest record.

I believe it is related to entity recreation because we had to recreate some entities changing the Ownership type to Organization instead of User or Team and this may have generated the issue. I also checked on other project implementation that the other team decided to start a brand new org instead of finding a solution for the issue and they had the same duplication (it was even worst because they had several duplicated records) and it worked like charm.

That being said try to apply the steps below to fix the issue:

  1. Use the script below to find the oldest duplicated records on CustomControlDefaultConfigBase

    select
    PrimaryEntityTypeCode,
    min(CreatedOn) oldest
    from
    CustomControlDefaultConfigBase
    where
    PrimaryEntityTypeCode in (select
    PrimaryEntityTypeCode
    from
    CustomControlDefaultConfigBase
    group by
    PrimaryEntityTypeCode
    having
    count(1) >1)
    group by
    PrimaryEntityTypeCode

  2. Delete these records and export the solution again (managed or unmanaged)
  3. Try to import it on the new environment

Thanks for the tips

Reply