This project has moved. For the latest updates, please go here.

Associate Entity - handling duplicates

Sep 22, 2016 at 4:01 PM
When using the Associate Entity activity, if a relationship already exists between the 2 records the workflow gets stuck in a waiting state with the message.

Cannot insert duplicate key.

Plugin Trace:

[msdyncrmWorkflowTools: msdyncrmWorkflowTools.AssociateEntity]
[msdyncrmWorkflowTools (1.0.33.0): Associate Entity]
Load CRM Service from context --- OK
ParentObjectTypeCode=10177--ParentId=83fb2c89-cedf-e511-80d3-00155dc86ae0


Error Message:

Unhandled Exception: Microsoft.Crm.CrmException: Cannot insert duplicate key.
at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)
at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)

We cannot evaluate if the relationship already exists, so how can we prevent the workflow remaining in this Waiting state. Ideally the activity would cancel if a duplicate key is found and allow any other workflow steps to complete so that the workflow can complete.
Coordinator
Nov 13, 2016 at 9:33 PM
Thank for the feedback, what you said have a lot of sense (both solutions).
I'm going to push it to my backlog ;) :
1) Ignore duplicate key insert error
2) New activity to check associations

regards!
Coordinator
Nov 18, 2016 at 10:37 PM
Done both changes today ;)
Nov 26, 2016 at 5:22 PM
Thanks, much appreciated - I'll download the new version and take a look at the changes/additions.
Nov 27, 2016 at 7:52 PM
Hi, downloaded and tested today. Unfortunately I still see the "Cannot Insert Duplicate Key" error on the Associate activity, so wanted to let you know as you said it would ignore it.
However, by adding the new Check Association activity to a condition I am now only running the Associate if it evaluates false so I'm able to bypass the error with a slight mod to my workflow :-)
Thanks!

Plugin Trace:

[msdyncrmWorkflowTools: msdyncrmWorkflowTools.AssociateEntity]
[msdyncrmWorkflowTools (1.0.34.0): Associate Entity]
Load CRM Service from context --- OK
ParentObjectTypeCode=10177--ParentId=81fb2c89-cedf-e511-80d3-00155dc86ae0


Error Message:

Unhandled Exception: Microsoft.Crm.CrmException: Cannot insert duplicate key.
at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)
at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)
Coordinator
Dec 6, 2016 at 10:28 AM
Sorry admgry, I opened an issue for this, and try to check it again.
thanks for the feedback ;)
Coordinator
Dec 6, 2016 at 8:59 PM
solved today.

thanks