web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Bulk N:N Association Request fails with "Message":"Cannot insert duplicate key.","ErrorCode":-2147220937"

(0) ShareShare
ReportReport
Posted on by

I am getting this error on the bulk N:N association request. I have confirmed that there is no request in the account that I am sending request to. I have checked the view on accoun too - the relationship are not inserted at all. I have disabled all duplicate detection rules, business flows, processes, business rules. I have disabled all the plugins (custom as well as microsoft; custom only; microsoft only - all variations) and the result has been inconsistent. Sometime I am able to repro the issue sometimes not. Below are the request details. Does anyone have any idea on what could be causing this issue?

{  
   "RequestName":"Associate",
   "Parameters":[  
      {  
         "Key":"Target",
         "Value":{  
            "Id":"b2478e0d-7de2-e111-a625-b8ac6f153db6",
            "LogicalName":"account",
            "Name":null,
            "KeyAttributes":[  

            ],
            "RowVersion":null
         }
      },
      {  
         "Key":"Relationship",
         "Value":{  
            "SchemaName":"tam_NN_account_new_CustomEntity",
            "PrimaryEntityRole":null
         }
      },
      {  
         "Key":"RelatedEntities",
         "Value":[  
            {  
               "Id":"b3f076c5-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"170173cb-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"a1357ad1-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"ae357ad1-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"7f8c9edd-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"8204bde3-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"c36ebfef-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"1395b9f5-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"3595b9f5-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"3a95b9f5-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"4095b9f5-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"4495b9f5-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"e402cafb-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"fa02cafb-f170-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"f7b5d51f-f270-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"0a93df31-f270-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"00fa0d4a-f270-e811-a839-000d3a37c642",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"85444e13-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"822a601f-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"e1715c25-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"203b5b3d-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"9af16749-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"a0f16749-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"b3f16749-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"ef6d5661-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"f06d5661-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"1a6e5661-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"1c6e5661-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"1e6e5661-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"94df5f73-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"96df5f73-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"97df5f73-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"89526a79-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"e9dd757f-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"f2dd757f-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"fcdd757f-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"09de757f-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"50de7f85-f270-e811-a838-000d3a37c0db",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"db3d426a-f270-e811-a83a-000d3a37c8e1",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"063e426a-f270-e811-a83a-000d3a37c8e1",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"073e426a-f270-e811-a83a-000d3a37c8e1",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"003e4370-f270-e811-a83a-000d3a37c8e1",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"1d3e4370-f270-e811-a83a-000d3a37c8e1",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"5d528694-f270-e811-a83a-000d3a37c8e1",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"addb869a-f270-e811-a83a-000d3a37c8e1",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"887a9fb2-f270-e811-a83a-000d3a37c8e1",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            },
            {  
               "Id":"b57a9fb2-f270-e811-a83a-000d3a37c8e1",
               "LogicalName":"new_CustomEntity",
               "Name":null,
               "KeyAttributes":[  

               ],
               "RowVersion":null
            }
         ]
      }
   ],
   "RequestId":null
},
BatchErrorResponse ={  
   "RequestIndex":0,
   "Response":null,
   "Fault":{  
      "TraceText":null,
      "InnerFault":{  
         "TraceText":null,
         "InnerFault":{  
            "TraceText":null,
            "InnerFault":null,
            "OriginalException":null,
            "ExceptionSource":null,
            "Message":"Cannot insert duplicate key.",
            "ErrorCode":-2147220937,
            "Timestamp":"2018-08-13T20:58:05.0068917Z",
            "ErrorDetails":[  

            ]
         },
         "OriginalException":null,
         "ExceptionSource":null,
         "Message":"Cannot insert duplicate key.",
         "ErrorCode":-2147220937,
         "Timestamp":"2018-08-13T20:58:05.0068917Z",
         "ErrorDetails":[  
            {  
               "Key":"ApiExceptionSourceKey",
               "Value":"Plugin/Microsoft.Crm.BusinessEntities.BusinessProcessObject"
            },
            {  
               "Key":"ApiOriginalExceptionKey",
               "Value":"Microsoft.Crm.BusinessEntities.CrmDuplicateRecordException: Cannot insert duplicate key. ---> Microsoft.Crm.BusinessEntities.CrmDuplicateRecordException: Cannot insert duplicate key.\r\n   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.ThrowDuplicateRecordException(IBusinessEntity entity, ExecutionContext context, SqlException e)\r\n   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.<>c__DisplayClass3_0.<Create>b__0()\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoCreate(IBusinessEntity entity, ExecutionContext context)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.CreateAssociation(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, ManyToManyEntityRelationship manyToManyRelationship, Relationship entityOneRelationship, Relationship entityTwoRelationship, Guid primaryKeyValue, ExecutionContext context)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.CreateAssociation(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, ManyToManyEntityRelationship manyToManyRelationship, Relationship entityOneRelationship, Relationship entityTwoRelationship, ExecutionContext context)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.HandleAssociationOperation(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, String associationRelationshipName, Boolean createAssociation, ExecutionContext context)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.AssociateEntities(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, String associationRelationshipName, ExecutionContext context)\r\n   --- End of inner exception stack trace ---\r\n   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)\r\n   at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)\r\n   at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass2_1.<Execute>b__0()"
            },
            {  
               "Key":"ApiStepKey",
               "Value":"56f5c774-9ecb-45f2-99c2-8dd57737af6e"
            },
            {  
               "Key":"ApiDepthKey",
               "Value":2
            },
            {  
               "Key":"ApiActivityIdKey",
               "Value":"614e39bc-9b74-455b-a005-7f1a87ae8f60"
            },
            {  
               "Key":"ApiPluginSolutionNameKey",
               "Value":"System"
            },
            {  
               "Key":"ApiStepSolutionNameKey",
               "Value":"System"
            }
         ]
      },
      "OriginalException":null,
      "ExceptionSource":null,
      "Message":"Cannot insert duplicate key.",
      "ErrorCode":-2147220937,
      "Timestamp":"2018-08-13T20:58:05.0068917Z",
      "ErrorDetails":[  
         {  
            "Key":"ApiExceptionSourceKey",
            "Value":"Plugin/Microsoft.Crm.BusinessEntities.BusinessProcessObject"
         },
         {  
            "Key":"ApiOriginalExceptionKey",
            "Value":"Microsoft.Crm.BusinessEntities.CrmDuplicateRecordException: Cannot insert duplicate key. ---> Microsoft.Crm.BusinessEntities.CrmDuplicateRecordException: Cannot insert duplicate key.\r\n   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.ThrowDuplicateRecordException(IBusinessEntity entity, ExecutionContext context, SqlException e)\r\n   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.<>c__DisplayClass3_0.<Create>b__0()\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoCreate(IBusinessEntity entity, ExecutionContext context)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.CreateAssociation(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, ManyToManyEntityRelationship manyToManyRelationship, Relationship entityOneRelationship, Relationship entityTwoRelationship, Guid primaryKeyValue, ExecutionContext context)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.CreateAssociation(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, ManyToManyEntityRelationship manyToManyRelationship, Relationship entityOneRelationship, Relationship entityTwoRelationship, ExecutionContext context)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.HandleAssociationOperation(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, String associationRelationshipName, Boolean createAssociation, ExecutionContext context)\r\n   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.AssociateEntities(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, String associationRelationshipName, ExecutionContext context)\r\n   --- End of inner exception stack trace ---\r\n   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)\r\n   at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)\r\n   at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass2_1.<Execute>b__0()"
         },
         {  
            "Key":"ApiStepKey",
            "Value":"56f5c774-9ecb-45f2-99c2-8dd57737af6e"
         },
         {  
            "Key":"ApiDepthKey",
            "Value":2
         },
         {  
            "Key":"ApiActivityIdKey",
            "Value":"614e39bc-9b74-455b-a005-7f1a87ae8f60"
         },
         {  
            "Key":"ApiPluginSolutionNameKey",
            "Value":"System"
         },
         {  
            "Key":"ApiStepSolutionNameKey",
            "Value":"System"
         }
      ]
   }
}
]
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    This error means there is already an association exist for one of the record you are trying to associate. Do an advance find and search for existing association. Check if any of the association matches wih the one you are trying to create.

    Hope this helps.

  • David Jennaway Profile Picture
    14,065 on at

    To expand on the previous answer, the Associate request does not check if the relationship already exists, but just throws an error if it already exists. It's your responsibility to ensure that the Associate request only contains relationships that don't already exist in CRM. This is a bit annoying, but that's the way it is

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans