Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

ServiceContext.SaveChanges() with Contact email unique key triggers CrmException

(0) ShareShare
ReportReport
Posted on by 5

Hi!

I'm using the Dynamics CRM's ServiceContext for some time now, because it is so convenient when you have a big tree of entities which you want to create (or update), especially with relationships inbetween them.

But after creating a unique key constraint (using an alternate key on the emailaddress1 field of the Contact entity), I sometimes get strange exceptions when calling the SaveChanges() method.

I call it strange, because when I check the SaveChangesResult's Result property which gets returned, I see a couple of entities in it (7-10 or something, but not the whole list of entities, which is ok, because it uses some sort of partitioning, according to Fiddler output), and the one that has an Error containing the:

A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.

message, is a new_relationship entity. It is a custom entity, which has 3 text fields, and a lookup to a contact:

im1.jpg

The contact entity inside of it has an EntityState of Changed, because we use duplicate detection to find it in the CRM, and changed some of it's values. It also has the real CRM guid as it's id.

For some reason, it seems to me, that at the backend it wants to create the contact entity again, even though it has a state of Changed.

Which makes it more weird to me, is that sometimes it succeeds when I try to debug it locally, and calling ServiceContext.SaveChanges() from there (but sometimes don't).

We are importing invoices btw, we use our custom new_invoice entity for that, and for an invoice we can get like 90-120 different related entities (contacts, accounts, line_items, taxes, parts, general_items, etc). On some of them, especially on the contact and account we use our own duplicate detection logic (VAT, email, etc), to update the duplicates only and not to re-create them.

I like working with the ServiceContext because it is so easy to create entities with relationships even when the given entities are not existing yet. For example:

var inv_rel = new new_invoice_relationship
                                            {
                                                new_desc = customer_or_company.relationship.desc,
                                                new_type = customer_or_company.relationship.type.ToString(),

                                                new_invoice_new_invoice_relationship = invoice,
                                                account_new_invoice_relationship = account
                                            };

                                            ServiceContext.AddObject(inv_rel);

Here, the account lookup can be a new account, with EntityState = null, or if it was found in the CRM, it has EntityState = Changed.

(Oh, and please don't get confused by the namings here, I purposely chose the new_relationship entity, which is (by the looks of it) throwing the exception for some reason, and which only describes how the current invoice entity is related to the given customer.)

Using fiddler I can see that SaveChanges() sends multiple commands to the Organization service:

im2.jpg

I attach the latest request, and response xml from fiddler, maybe you can see something in it.

Request xml (the Execute part only):

	
		
			
				Target
				
					
						
							new_desc
							
						
						
							new_type
							INV
						
						
							new_invoice_relationshipid
							a27aa3d4-863f-ea11-84cb-b4692153b9fb
						
					
					Created
					
					a27aa3d4-863f-ea11-84cb-b4692153b9fb
					
					new_invoice_relationship
					
						
							
								
								new_invoice_new_invoice_relationship
							
							
								
									
										
											
												new_name
												Invoice - ********/2020
											
											
												new_date
												2020-01-21T00:00:00
											
											
												new_number
												***************
											
											
												new_po_no
												
											
											
												new_currency
												HUF
											
											
												new_document_type
												DEL
											
											
												new_total
												44242.36
											
											
												new_dealer_warehouse
												
											
											
												new_xml_file_name
												***********************
											
											
												new_fix_classification_relationship_added
												true
											
											
												new_added_to_multilookup
												true
											
											
												new_invoiceid
												987aa3d4-863f-ea11-84cb-b4692153b9fb
											
										
										Unchanged
										
										987aa3d4-863f-ea11-84cb-b4692153b9fb
										
										new_invoice
										
										
									
								
								new_invoice
								
								false
								
								0
								false
							
						
						
							
								
								contact_new_invoice_relationship
							
							
								
									
										
											
												customertypecode
												
													1
												
											
											
												new_mobilephone_original
												***********
											
											
												mobilephone
												***********
											
											
												merged
												false
											
											
												new_donotphonehome
												true
											
											
												gendercode
												
													2
												
											
											
												new_language_code
												*****
											
											
												territorycode
												
													1
												
											
											
												emailaddress1
												******@******.com
											
											
												haschildrencode
												
													1
												
											
											
												preferredappointmenttimecode
												
													1
												
											
											
												new_record_shared
												true
											
											
												isbackofficecustomer
												false
											
											
												new_datacleanstatus
												
													100000001
												
											
											
												msdyn_orgchangestatus
												
													0
												
											
											
												owninguser
												
													c23043eb-1466-4012-9781-6ce5675dc173
													
													systemuser
													
													
												
											
											
												address1_composite
												*********

*****

***
											
											
												lastname
												*******
											
											
												donotpostalmail
												false
											
											
												marketingonly
												false
											
											
												donotphone
												false
											
											
												preferredcontactmethodcode
												
													1
												
											
											
												educationcode
												
													1
												
											
											
												ownerid
												
													c23043eb-1466-4012-9781-6ce5675dc173
													
													systemuser
													crm admin
													
												
											
											
												customersizecode
												
													1
												
											
											
												firstname
												***********
											
											
												yomifullname
												***********
											
											
												address2_addresstypecode
												
													1
												
											
											
												address1_line1
												************
											
											
												donotemail
												true
											
											
												address2_shippingmethodcode
												
													1
												
											
											
												fullname
												***************
											
											
												address1_addressid
												123c94b9-bf39-4f63-be6d-15d70f21e607
											
											
												msdyn_gdproptout
												false
											
											
												address2_freighttermscode
												
													1
												
											
											
												statuscode
												
													1
												
											
											
												createdon
												2019-02-19T21:46:46Z
											
											
												new_parent_id
												*********
											
											
												new_preferred_dealer
												*********
											
											
												business2
												*********
											
											
												donotsendmm
												false
											
											
												donotfax
												false
											
											
												new_share_record
												true
											
											
												leadsourcecode
												
													1
												
											
											
												address1_country
												*********
											
											
												followemail
												true
											
											
												modifiedon
												2020-01-24T13:27:23Z
											
											
												creditonhold
												false
											
											
												address3_addressid
												c053e4b8-48eb-4f47-8b61-107f87dd1635
											
											
												donotbulkemail
												false
											
											
												modifiedby
												
													c23043eb-1466-4012-9781-6ce5675dc173
													
													systemuser
													crm admin
													
												
											
											
												new_donotphonebusinness
												true
											
											
												shippingmethodcode
												
													1
												
											
											
												createdby
												
													c23043eb-1466-4012-9781-6ce5675dc173
													
													systemuser
													crm admin
													
												
											
											
												new_donotphonesms
												true
											
											
												address1_city
												***********
											
											
												donotbulkpostalmail
												false
											
											
												contactid
												4f0ea3d9-8f34-e911-867a-0003ff4c4e0b
											
											
												new_datacleansingscript
												true
											
											
												participatesinworkflow
												false
											
											
												statecode
												
													0
												
											
											
												owningbusinessunit
												
													7d6baed2-851b-e911-a960-000d3a29f363
													
													businessunit
													
													
												
											
											
												new_cust_id
												************
											
											
												address2_addressid
												6e5b561d-7c82-41af-87cf-4ab680cfcc43
											
											
												address1_postalcode
												***********
											
											
												new_business2_original
												***********
											
											
												telephone1
												***********
											
											
												new_phone_businness_opt_in_date_time
												2018-12-10T00:00:00
											
											
												new_donotphonebusinness_scope
												A
											
											
												new_email_opt_in_date_time
												2018-12-10T00:00:00
											
											
												new_donotemail_scope
												A
											
											
												new_phone_home_opt_in_date_time
												2018-12-10T00:00:00
											
											
												new_donotphonehome_scope
												A
											
											
												new_phone_opt_in_date_time
												2018-12-10T00:00:00
											
											
												new_donotphone_scope
												A
											
											
												new_sms_opt_in_date_time
												2018-12-10T00:00:00
											
											
												new_donotphonesms_scope
												A
											
											
												new_fax_opt_in_date_time
												2018-12-10T00:00:00
											
											
												new_donotfax_scope
												A
											
											
												new_postal_mail_opt_in_date_time
												2018-12-10T00:00:00
											
											
												new_donotpostalmail_scope
												A
											
											
												new_donotsharedata
												true
											
											
												new_data_forwarding_opt_in_date_time
												2018-12-10T00:00:00
											
											
												new_donotsharedata_scope
												A
											
										
										Changed
										
											
												customertypecode
												Default Value
											
											
												merged
												No
											
											
												new_donotphonehome
												Allow
											
											
												gendercode
												Female
											
											
												territorycode
												Default Value
											
											
												haschildrencode
												Default Value
											
											
												preferredappointmenttimecode
												Morning
											
											
												new_record_shared
												True
											
											
												isbackofficecustomer
												No
											
											
												new_datacleanstatus
												Clean
											
											
												msdyn_orgchangestatus
												No Feedback
											
											
												donotpostalmail
												Allow
											
											
												marketingonly
												No
											
											
												donotphone
												Allow
											
											
												preferredcontactmethodcode
												Any
											
											
												educationcode
												Default Value
											
											
												ownerid
												crm admin
											
											
												customersizecode
												Default Value
											
											
												address2_addresstypecode
												Default Value
											
											
												donotemail
												Allow
											
											
												address2_shippingmethodcode
												Default Value
											
											
												msdyn_gdproptout
												No
											
											
												address2_freighttermscode
												Default Value
											
											
												statuscode
												Active
											
											
												createdon
												2/19/2019 9:46 PM
											
											
												new_parent_id
												*******
											
											
												donotsendmm
												Do Not Send
											
											
												donotfax
												Do Not Allow
											
											
												new_share_record
												True
											
											
												leadsourcecode
												Default Value
											
											
												followemail
												Allow
											
											
												modifiedon
												1/24/2020 1:27 PM
											
											
												creditonhold
												No
											
											
												donotbulkemail
												Do Not Allow
											
											
												modifiedby
												crm admin
											
											
												new_donotphonebusinness
												Allow
											
											
												shippingmethodcode
												Default Value
											
											
												createdby
												crm admin
											
											
												new_donotphonesms
												Allow
											
											
												donotbulkpostalmail
												No
											
											
												new_datacleansingscript
												Yes
											
											
												participatesinworkflow
												No
											
											
												statecode
												Active
											
										
										4f0ea3d9-8f34-e911-867a-0003ff4c4e0b
										
										contact
										
										252500091
									
								
								contact
								
								false
								
								0
								false
							
						
					
					
				
			
		
		
		Create
	

And the response, containing the exception:

	
		http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/ExecuteOrganizationServiceFaultFault
		urn:uuid:673c84eb-0318-4305-b8b0-7be7924f01e6
		00000000-0000-0000-0000-000000000000
		
			
				2020-01-25T15:24:59.669Z
				2020-01-25T15:29:59.669Z
			
		
	
	
		
			
				s:Sender
			
			
				A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
			
			
				
					baa5a4b8-20c6-4d59-a6e8-6397ff891553
					-2147088238
					
						
							ApiExceptionSourceKey
							Plugin/Microsoft.Crm.Common.ObjectModel.ContactService
						
						
							ApiOriginalExceptionKey
							Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again. ---> Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.

   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.ThrowDuplicateRecordException(IBusinessEntity entity, ExecutionContext context, SqlException e)

   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.Update(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)

   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoUpdate(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)

   --- End of inner exception stack trace ---

   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)

   at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)

   at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass3_0.b__0()
						
						
							ApiStepKey
							90750cb3-cfdc-db11-8341-0019b9204da9
						
						
							ApiDepthKey
							2
						
						
							ApiActivityIdKey
							baa5a4b8-20c6-4d59-a6e8-6397ff891553
						
						
							ApiPluginSolutionNameKey
							System
						
						
							ApiStepSolutionNameKey
							System
						
						
							ApiExceptionCategory
							ClientError
						
						
							ApiExceptionMesageName
							DuplicateRecordEntityKey
						
						
							ApiExceptionHttpStatusCode
							412
						
						
							DuplicateEntity
							******************************************
						
						
							DuplicateAttributes
							**********@*******.com
						
					
					http://go.microsoft.com/fwlink/?LinkID=398563&error=Microsoft.Crm.CrmException:80060892&client=platform
					A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
					2020-01-25T15:24:59.6694242Z
					false
					
					
						baa5a4b8-20c6-4d59-a6e8-6397ff891553
						-2147088238
						
							
								ApiExceptionSourceKey
								Plugin/Microsoft.Crm.Common.ObjectModel.ContactService
							
							
								ApiOriginalExceptionKey
								Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again. ---> Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.

   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.ThrowDuplicateRecordException(IBusinessEntity entity, ExecutionContext context, SqlException e)

   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.Update(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)

   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoUpdate(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)

   --- End of inner exception stack trace ---

   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)

   at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)

   at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass3_0.b__0()
							
							
								ApiStepKey
								90750cb3-cfdc-db11-8341-0019b9204da9
							
							
								ApiDepthKey
								2
							
							
								ApiActivityIdKey
								baa5a4b8-20c6-4d59-a6e8-6397ff891553
							
							
								ApiPluginSolutionNameKey
								System
							
							
								ApiStepSolutionNameKey
								System
							
							
								ApiExceptionCategory
								ClientError
							
							
								ApiExceptionMesageName
								DuplicateRecordEntityKey
							
							
								ApiExceptionHttpStatusCode
								412
							
						
						
						A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
						2020-01-25T15:24:59.6694242Z
						false
						
						
							baa5a4b8-20c6-4d59-a6e8-6397ff891553
							-2147088238
							
								
									ApiExceptionSourceKey
									Plugin/Microsoft.Crm.Common.ObjectModel.ContactService
								
								
									ApiOriginalExceptionKey
									Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again. ---> Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.

   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.ThrowDuplicateRecordException(IBusinessEntity entity, ExecutionContext context, SqlException e)

   at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.Update(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)

   at Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoUpdate(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)

   --- End of inner exception stack trace ---

   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)

   at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)

   at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass3_0.b__0()
								
								
									ApiStepKey
									90750cb3-cfdc-db11-8341-0019b9204da9
								
								
									ApiDepthKey
									2
								
								
									ApiActivityIdKey
									baa5a4b8-20c6-4d59-a6e8-6397ff891553
								
								
									ApiPluginSolutionNameKey
									System
								
								
									ApiStepSolutionNameKey
									System
								
								
									ApiExceptionCategory
									ClientError
								
								
									ApiExceptionMesageName
									DuplicateRecordEntityKey
								
								
									ApiExceptionHttpStatusCode
									412
								
							
							
							A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
							2020-01-25T15:24:59.6694242Z
							false
							
							
								baa5a4b8-20c6-4d59-a6e8-6397ff891553
								-2147088238
								
								
								A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
								2020-01-25T15:24:59.6694242Z
								false
								
								
								
								
							
							
							
						
						
						
					
					
					
				
			
		
	

As for me,  it looks ok. It wants to create a new_invoice_relationship entity, which has two related entities in it.

One is the new_invoice entity itself, which has an EntityState of Unchanged.

The second one is a Contact entity (through the contact_new_invoice_relationship field) and it has an EntityState of Changed, which is correct becase some values are updated.

I wish someone could help, or point me in the right direction. Sorry for the lenghty description. I can provide more info, if you need!

It's a very annoying problem for me.

Any ideas?

Thanks in advance,

Attila

  • xaint Profile Picture
    xaint 5 on at
    RE: ServiceContext.SaveChanges() with Contact email unique key triggers CrmException

    Hi!

    It is version 1710 (9.1.0.12056) online.

    Opening a support request may be a good idea, thanks!

    Unfortunately I cannot share the whole entitiy relationship diagram. :(

    What I'm trying to do now, is to narrow the list of entities down (that would end up in the ServiceContext at the end of the day).

    So narrowing it down to just a new_invoice entity which has no lookups added, and using one Contact entity (an existing one, with valid GUID and an EntityState of Changed) and one new_invoice_relationship entity which has 2-3 text fields and two lookups for the two others above (contact and invoice).

    I'm adding the lookups using the generated proxy classes' lookup fields directly:

    var inv_rel = new new_invoice_relationship
    {
        new_desc = customer_or_company.relationship.desc,
        new_type = customer_or_company.relationship.type.ToString(),
    
        // Lookups
        new_invoice_new_invoice_relationship = invoice,
        contact_new_invoice_relationship = contact
    };
    
    ServiceContext.AddObject(inv_rel);

    So I don't use the ServiceContext.AddLink method, because I found it too cumbersome compared to the above method, which adds the relationships automatically I presume...

    And the result is: another exception:

    The new_invoice (Id = f05ff6fc-3c41-ea11-84cc-b4692153b9f8) in the "new_invoice_new_invoice_relationship." relationship with the new_invoice_relationship (Id = ef5ff6fc-3c41-ea11-84cc-b4692153b9f8) doesn't exist.

    It seems that it tries to create the entities in the wrong order? (The guids are generated on the client, not yet in the CRM).

    I'll attach the request and response at the end.

    But no worries I thought, I'll use the ServiceProxy to create the invoice before calling the ServiceContext.SaveChanges(), like so:

    invoice.Id = ServiceProxy.Create(invoice);
    ServiceContext.Attach(invoice);

    That fixes the "The invoice doesn't exist" problem, but then I'm back at the original problem which is:

    A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.

    I'm trying to open a support ticket with the actual request (and response) xmls that are sent to the Dynamics CRM by the ServiceContext, maybe they can point me to the right direction..

    Some (long) request and response xmls:

    A request & response with the following entities in it:

    • new_extract (updated)
    • new_dealer (updated)
    • new_invoice (created)
    • Contact (updated)
    • new_invoice_relationship (created) (lookups to Contact & new_invoice)

    Here the invoice is NOT yet created using the ServiceProxy..

    	
    		
    			
    				Target
    				
    					
    						
    							new_desc
    							
    						
    						
    							new_type
    							INV
    						
    						
    							new_invoice_relationshipid
    							ef5ff6fc-3c41-ea11-84cc-b4692153b9f8
    						
    					
    					Created
    					
    					ef5ff6fc-3c41-ea11-84cc-b4692153b9f8
    					
    					new_invoice_relationship
    					
    						
    							
    								
    								new_invoice_new_invoice_relationship
    							
    							
    								
    									
    										
    											
    												new_name
    												Invoice - ************
    											
    											
    												new_date
    												2020-01-21T00:00:00
    											
    											
    												new_number
    												************
    											
    											
    												new_po_no
    												
    											
    											
    												new_currency
    												************
    											
    											
    												new_document_type
    												************
    											
    											
    												new_total
    												1111.11
    											
    											
    												new_dealer_warehouse
    												
    											
    											
    												new_xml_file_name
    												************
    											
    											
    												new_fix_classification_relationship_added
    												true
    											
    											
    												new_added_to_multilookup
    												true
    											
    											
    												new_invoiceid
    												f05ff6fc-3c41-ea11-84cc-b4692153b9f8
    											
    										
    										Created
    										
    										f05ff6fc-3c41-ea11-84cc-b4692153b9f8
    										
    										new_invoice
    										
    											
    												
    													
    													new_extract_new_invoice
    												
    												
    													
    														
    															
    																
    																	new_last_extract
    																	
    																		f4217845-743d-ea11-8454-0003ff4c6b1a
    																		
    																		new_extract
    																		
    																		247951844
    																	
    																
    																
    																	owningbusinessunit
    																	
    																		7d6baed2-851b-e911-a960-000d3a29f363
    																		
    																		businessunit
    																		
    																		
    																	
    																
    																
    																	statecode
    																	
    																		0
    																	
    																
    																
    																	statuscode
    																	
    																		1
    																	
    																
    																
    																	createdby
    																	
    																		c23043eb-1466-4012-9781-6ce5675dc173
    																		
    																		systemuser
    																		crm admin
    																		
    																	
    																
    																
    																	timezoneruleversionnumber
    																	4
    																
    																
    																	new_extractid
    																	b995a55c-bb3e-ea11-8454-0003ff4c72e6
    																
    																
    																	ownerid
    																	
    																		c23043eb-1466-4012-9781-6ce5675dc173
    																		
    																		systemuser
    																		crm admin
    																		
    																	
    																
    																
    																	modifiedon
    																	2020-01-27T18:31:14Z
    																
    																
    																	owninguser
    																	
    																		c23043eb-1466-4012-9781-6ce5675dc173
    																		
    																		systemuser
    																		
    																		
    																	
    																
    																
    																	modifiedby
    																	
    																		c23043eb-1466-4012-9781-6ce5675dc173
    																		
    																		systemuser
    																		crm admin
    																		
    																	
    																
    																
    																	new_name
    																	Extract - ************
    																
    																
    																	createdon
    																	2020-01-24T15:08:27Z
    																
    																
    																	new_extract_id
    																	************
    																
    																
    																	new_date
    																	2020-01-21T00:00:00
    																
    															
    															Changed
    															
    																
    																	new_last_extract
    																	608
    																
    																
    																	statecode
    																	Active
    																
    																
    																	statuscode
    																	Active
    																
    																
    																	createdby
    																	crm admin
    																
    																
    																	timezoneruleversionnumber
    																	4
    																
    																
    																	ownerid
    																	crm admin
    																
    																
    																	modifiedon
    																	1/27/2020 6:31 PM
    																
    																
    																	modifiedby
    																	crm admin
    																
    																
    																	createdon
    																	1/24/2020 3:08 PM
    																
    																
    																	new_date
    																	1/21/2020 12:00 AM
    																
    															
    															b995a55c-bb3e-ea11-8454-0003ff4c72e6
    															
    															new_extract
    															
    															267249766
    														
    													
    													new_extract
    													
    													false
    													
    													0
    													false
    												
    											
    											
    												
    													
    													new_dealer_new_invoice
    												
    												
    													
    														
    															
    																REMOVED, IT'S IRRELEVANT
    															
    															Changed
    															
    																REMOVED, IT'S IRRELEVANT
    															
    															9913b8a2-2723-e911-9462-0003ff4c4a7f
    															
    															new_dealer
    															
    															267249820
    														
    													
    													new_dealer
    													
    													false
    													
    													0
    													false
    												
    											
    										
    										
    									
    								
    								new_invoice
    								
    								false
    								
    								0
    								false
    							
    						
    						
    							
    								
    								contact_new_invoice_relationship
    							
    							
    								
    									
    										
    											
    												customertypecode
    												
    													1
    												
    											
    											
    												new_mobilephone_original
    												***************
    											
    											
    												mobilephone
    												***************
    											
    											
    												merged
    												false
    											
    											
    												new_donotphonehome
    												***************
    											
    											
    												gendercode
    												
    													2
    												
    											
    											
    												new_language_code
    												***************
    											
    											
    												territorycode
    												
    													1
    												
    											
    											
    												emailaddress1
    												***************
    											
    											
    												haschildrencode
    												
    													1
    												
    											
    											
    												preferredappointmenttimecode
    												
    													1
    												
    											
    											
    												new_record_shared
    												***************
    											
    											
    												isbackofficecustomer
    												***************
    											
    											
    												new_datacleanstatus
    												
    													100000001
    												
    											
    											
    												msdyn_orgchangestatus
    												
    													0
    												
    											
    											
    												owninguser
    												
    													c23043eb-1466-4012-9781-6ce5675dc173
    													
    													systemuser
    													
    													
    												
    											
    											
    												address1_composite
    												***************
    											
    											
    												lastname
    												***************
    											
    											
    												donotpostalmail
    												***************
    											
    											
    												marketingonly
    												***************
    											
    											
    												donotphone
    												***************
    											
    											
    												preferredcontactmethodcode
    												
    													1
    												
    											
    											
    												educationcode
    												
    													1
    												
    											
    											
    												ownerid
    												
    													c23043eb-1466-4012-9781-6ce5675dc173
    													
    													systemuser
    													crm admin
    													
    												
    											
    											
    												customersizecode
    												
    													1
    												
    											
    											
    												firstname
    												***************
    											
    											
    												yomifullname
    												***************
    											
    											
    												address2_addresstypecode
    												
    													1
    												
    											
    											
    												address1_line1
    												***************
    											
    											
    												donotemail
    												***************
    											
    											
    												address2_shippingmethodcode
    												
    													1
    												
    											
    											
    												fullname
    												***************
    											
    											
    												address1_addressid
    												123c94b9-bf39-4f63-be6d-15d70f21e607
    											
    											
    												msdyn_gdproptout
    												false
    											
    											
    												address2_freighttermscode
    												
    													1
    												
    											
    											
    												statuscode
    												
    													1
    												
    											
    											
    												createdon
    												2019-02-19T21:46:46Z
    											
    											
    												new_parent_id
    												***************
    											
    											
    												new_preferred_dealer
    												***************
    											
    											
    												business2
    												***************
    											
    											
    												donotsendmm
    												***************
    											
    											
    												donotfax
    												***************
    											
    											
    												new_share_record
    												***************
    											
    											
    												leadsourcecode
    												
    													1
    												
    											
    											
    												address1_country
    												***************
    											
    											
    												followemail
    												***************
    											
    											
    												modifiedon
    												2020-01-24T13:27:23Z
    											
    											
    												creditonhold
    												***************
    											
    											
    												address3_addressid
    												c053e4b8-48eb-4f47-8b61-107f87dd1635
    											
    											
    												donotbulkemail
    												false
    											
    											
    												modifiedby
    												
    													c23043eb-1466-4012-9781-6ce5675dc173
    													
    													systemuser
    													crm admin
    													
    												
    											
    											
    												new_donotphonebusinness
    												***************
    											
    											
    												shippingmethodcode
    												
    													1
    												
    											
    											
    												createdby
    												
    													c23043eb-1466-4012-9781-6ce5675dc173
    													
    													systemuser
    													crm admin
    													
    												
    											
    											
    												new_donotphonesms
    												***************
    											
    											
    												address1_city
    												***************
    											
    											
    												donotbulkpostalmail
    												***************
    											
    											
    												contactid
    												4f0ea3d9-8f34-e911-867a-0003ff4c4e0b
    											
    											
    												new_datacleansingscript
    												***************
    											
    											
    												participatesinworkflow
    												***************
    											
    											
    												statecode
    												
    													0
    												
    											
    											
    												owningbusinessunit
    												
    													7d6baed2-851b-e911-a960-000d3a29f363
    													
    													businessunit
    													
    													
    												
    											
    											
    												new_cust_id
    												***************
    											
    											
    												address2_addressid
    												6e5b561d-7c82-41af-87cf-4ab680cfcc43
    											
    											
    												address1_postalcode
    												***************
    											
    											
    												new_business2_original
    												***************
    											
    											
    												telephone1
    												***************
    											
    											
    												new_phone_businness_opt_in_date_time
    												***************
    											
    											
    												new_donotphonebusinness_scope
    												***************
    											
    											
    												new_email_opt_in_date_time
    												***************
    											
    											
    												new_donotemail_scope
    												***************
    											
    											
    												new_phone_home_opt_in_date_time
    												***************
    											
    											
    												new_donotphonehome_scope
    												***************
    											
    											
    												new_phone_opt_in_date_time
    												***************
    											
    											
    												new_donotphone_scope
    												***************
    											
    											
    												new_sms_opt_in_date_time
    												***************
    											
    											
    												new_donotphonesms_scope
    												***************
    											
    											
    												new_fax_opt_in_date_time
    												***************
    											
    											
    												new_donotfax_scope
    												***************
    											
    											
    												new_postal_mail_opt_in_date_time
    												***************
    											
    											
    												new_donotpostalmail_scope
    												***************
    											
    											
    												new_donotsharedata
    												***************
    											
    											
    												new_data_forwarding_opt_in_date_time
    												***************
    											
    											
    												new_donotsharedata_scope
    												***************
    											
    										
    										Changed
    										
    											
    												customertypecode
    												Default Value
    											
    											
    												merged
    												No
    											
    											
    												new_donotphonehome
    												***************
    											
    											
    												gendercode
    												***************
    											
    											
    												territorycode
    												Default Value
    											
    											
    												haschildrencode
    												Default Value
    											
    											
    												preferredappointmenttimecode
    												***************
    											
    											
    												new_record_shared
    												***************
    											
    											
    												isbackofficecustomer
    												No
    											
    											
    												new_datacleanstatus
    												***************
    											
    											
    												msdyn_orgchangestatus
    												No Feedback
    											
    											
    												donotpostalmail
    												***************
    											
    											
    												marketingonly
    												***************
    											
    											
    												donotphone
    												***************
    											
    											
    												preferredcontactmethodcode
    												Any
    											
    											
    												educationcode
    												Default Value
    											
    											
    												ownerid
    												crm admin
    											
    											
    												customersizecode
    												Default Value
    											
    											
    												address2_addresstypecode
    												Default Value
    											
    											
    												donotemail
    												***************
    											
    											
    												address2_shippingmethodcode
    												Default Value
    											
    											
    												msdyn_gdproptout
    												No
    											
    											
    												address2_freighttermscode
    												Default Value
    											
    											
    												statuscode
    												Active
    											
    											
    												createdon
    												2/19/2019 9:46 PM
    											
    											
    												new_parent_id
    												***************
    											
    											
    												donotsendmm
    												Do Not Send
    											
    											
    												donotfax
    												Do Not Allow
    											
    											
    												new_share_record
    												True
    											
    											
    												leadsourcecode
    												Default Value
    											
    											
    												followemail
    												Allow
    											
    											
    												modifiedon
    												1/24/2020 1:27 PM
    											
    											
    												creditonhold
    												No
    											
    											
    												donotbulkemail
    												Do Not Allow
    											
    											
    												modifiedby
    												crm admin
    											
    											
    												new_donotphonebusinness
    												Allow
    											
    											
    												shippingmethodcode
    												Default Value
    											
    											
    												createdby
    												crm admin
    											
    											
    												new_donotphonesms
    												***************
    											
    											
    												donotbulkpostalmail
    												No
    											
    											
    												new_datacleansingscript
    												***************
    											
    											
    												participatesinworkflow
    												No
    											
    											
    												statecode
    												Active
    											
    										
    										4f0ea3d9-8f34-e911-867a-0003ff4c4e0b
    										
    										contact
    										
    										252500091
    									
    								
    								contact
    								
    								false
    								
    								0
    								false
    							
    						
    					
    					
    				
    			
    		
    		
    		Create
    	
    

    Response:

    	
    		http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/ExecuteOrganizationServiceFaultFault
    		urn:uuid:d8b21d70-2e1f-49f8-bc6d-c6f865b53204
    		00000000-0000-0000-0000-000000000000
    		
    			
    				2020-01-27T19:41:22.307Z
    				2020-01-27T19:46:22.307Z
    			
    		
    	
    	
    		
    			
    				s:Sender
    			
    			
    				The new_invoice (Id = f05ff6fc-3c41-ea11-84cc-b4692153b9f8) in the "new_invoice_new_invoice_relationship." relationship with the new_invoice_relationship (Id = ef5ff6fc-3c41-ea11-84cc-b4692153b9f8) doesn't exist.
    			
    			
    				
    					d23cc44e-a1d7-41e0-a983-ef4cab624d0b
    					-2147220969
    					
    						
    							ApiExceptionSourceKey
    							Plugin/Microsoft.Crm.ObjectModel.CustomBusinessEntityService
    						
    						
    							ApiOriginalExceptionKey
    							Microsoft.Crm.CrmException: The new_invoice (Id = f05ff6fc-3c41-ea11-84cc-b4692153b9f8) in the "new_invoice_new_invoice_relationship." relationship with the new_invoice_relationship (Id = ef5ff6fc-3c41-ea11-84cc-b4692153b9f8) doesn't exist. ---> Microsoft.Crm.CrmException: The new_invoice (Id = f05ff6fc-3c41-ea11-84cc-b4692153b9f8) in the "new_invoice_new_invoice_relationship." relationship with the new_invoice_relationship (Id = ef5ff6fc-3c41-ea11-84cc-b4692153b9f8) doesn't exist.
    
       at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.HandleRelatedEntities(BusinessEntity primaryEntity, EntityState defaultState, ExecutionContext context)
    
       at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.CreateWithRelatedEntities(BusinessEntity entity, ExecutionContext context)
    
       at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.CreateWithInvocationSource(BusinessEntity entity, Int32 invocationSource, ExecutionContext context)
    
       at Microsoft.Crm.BusinessEntities.BusinessProcessObject.<>c__DisplayClass179_0.b__0()
    
       at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)
    
       at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)
    
       --- End of inner exception stack trace ---
    
       at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
    
       at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
    
       at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass3_0.b__0()
    						
    						
    							ApiStepKey
    							248fdd0d-47d5-e911-a85f-000d3a45a408
    						
    						
    							ApiDepthKey
    							1
    						
    						
    							ApiActivityIdKey
    							d23cc44e-a1d7-41e0-a983-ef4cab624d0b
    						
    						
    							ApiPluginSolutionNameKey
    							System
    						
    						
    							ApiStepSolutionNameKey
    							System
    						
    						
    							ApiExceptionCategory
    							ClientError
    						
    						
    							ApiExceptionMesageName
    							ObjectDoesNotExist
    						
    						
    							ApiExceptionHttpStatusCode
    							404
    						
    					
    					http://go.microsoft.com/fwlink/?LinkID=398563&error=Microsoft.Crm.CrmException:80040217&client=platform
    					The new_invoice (Id = f05ff6fc-3c41-ea11-84cc-b4692153b9f8) in the "new_invoice_new_invoice_relationship." relationship with the new_invoice_relationship (Id = ef5ff6fc-3c41-ea11-84cc-b4692153b9f8) doesn't exist.
    					2020-01-27T19:41:22.3075256Z
    					false
    					
    					
    						d23cc44e-a1d7-41e0-a983-ef4cab624d0b
    						-2147220969
    						
    						
    						The new_invoice (Id = f05ff6fc-3c41-ea11-84cc-b4692153b9f8) in the "new_invoice_new_invoice_relationship." relationship with the new_invoice_relationship (Id = ef5ff6fc-3c41-ea11-84cc-b4692153b9f8) doesn't exist.
    						2020-01-27T19:41:22.3075256Z
    						false
    						
    						
    						
    						
    					
    					
    					
    				
    			
    		
    	
    

    Here the invoice is CREATED beforehand using the ServiceProxy.Create method, to avoid the above exception.

    I've also removed the new_extract, and new_dealer entities from the list, because they are irrelevant. So the only entities here are:

    • new_invoice (already existing, Unchanged)
    • new_invoice_relationship (created)
    • Contact (changed)

    Request:

    	
    		
    			
    				Target
    				
    					
    						
    							new_desc
    							
    						
    						
    							new_type
    							INV
    						
    						
    							new_invoice_relationshipid
    							2a79375b-4041-ea11-84cc-b4692153b9f8
    						
    					
    					Created
    					
    					2a79375b-4041-ea11-84cc-b4692153b9f8
    					
    					new_invoice_relationship
    					
    						
    							
    								
    								new_invoice_new_invoice_relationship
    							
    							
    								
    									
    										
    											
    												new_name
    												Invoice ************
    											
    											
    												new_date
    												2020-01-21T00:00:00
    											
    											
    												new_number
    												************
    											
    											
    												new_po_no
    												
    											
    											
    												new_currency
    												************
    											
    											
    												new_document_type
    												************
    											
    											
    												new_total
    												11111.11
    											
    											
    												new_dealer_warehouse
    												
    											
    											
    												new_xml_file_name
    												************
    											
    											
    												new_fix_classification_relationship_added
    												************
    											
    											
    												new_added_to_multilookup
    												************
    											
    											
    												new_invoiceid
    												5231be56-3f41-ea11-a812-000d3a49daf7
    											
    										
    										Unchanged
    										
    										5231be56-3f41-ea11-a812-000d3a49daf7
    										
    										new_invoice
    										
    										
    									
    								
    								new_invoice
    								
    								false
    								
    								0
    								false
    							
    						
    						
    							
    								
    								contact_new_invoice_relationship
    							
    							
    								
    									
    										
    											
    												customertypecode
    												
    													1
    												
    											
    											
    												new_mobilephone_original
    												************
    											
    											
    												mobilephone
    												************
    											
    											
    												merged
    												false
    											
    											
    												new_donotphonehome
    												************
    											
    											
    												gendercode
    												
    													2
    												
    											
    											
    												new_language_code
    												************
    											
    											
    												territorycode
    												
    													1
    												
    											
    											
    												emailaddress1
    												************
    											
    											
    												haschildrencode
    												
    													1
    												
    											
    											
    												preferredappointmenttimecode
    												
    													1
    												
    											
    											
    												new_record_shared
    												************
    											
    											
    												isbackofficecustomer
    												************
    											
    											
    												new_datacleanstatus
    												
    													100000001
    												
    											
    											
    												msdyn_orgchangestatus
    												
    													0
    												
    											
    											
    												owninguser
    												
    													c23043eb-1466-4012-9781-6ce5675dc173
    													
    													systemuser
    													
    													
    												
    											
    											
    												address1_composite
    												************
    											
    											
    												lastname
    												************
    											
    											
    												donotpostalmail
    												true
    											
    											
    												marketingonly
    												false
    											
    											
    												donotphone
    												true
    											
    											
    												preferredcontactmethodcode
    												
    													1
    												
    											
    											
    												educationcode
    												
    													1
    												
    											
    											
    												ownerid
    												
    													c23043eb-1466-4012-9781-6ce5675dc173
    													
    													systemuser
    													crm admin
    													
    												
    											
    											
    												customersizecode
    												
    													1
    												
    											
    											
    												firstname
    												************
    											
    											
    												yomifullname
    												************
    											
    											
    												address2_addresstypecode
    												
    													1
    												
    											
    											
    												address1_line1
    												************
    											
    											
    												donotemail
    												************
    											
    											
    												address2_shippingmethodcode
    												
    													1
    												
    											
    											
    												fullname
    												************
    											
    											
    												address1_addressid
    												123c94b9-bf39-4f63-be6d-15d70f21e607
    											
    											
    												msdyn_gdproptout
    												************
    											
    											
    												address2_freighttermscode
    												
    													1
    												
    											
    											
    												statuscode
    												
    													1
    												
    											
    											
    												createdon
    												2019-02-19T21:46:46Z
    											
    											
    												new_parent_id
    												************
    											
    											
    												new_preferred_dealer
    												************
    											
    											
    												business2
    												************
    											
    											
    												donotsendmm
    												************
    											
    											
    												donotfax
    												************
    											
    											
    												new_share_record
    												************
    											
    											
    												leadsourcecode
    												
    													1
    												
    											
    											
    												address1_country
    												************
    											
    											
    												followemail
    												************
    											
    											
    												modifiedon
    												2020-01-24T13:27:23Z
    											
    											
    												creditonhold
    												************
    											
    											
    												address3_addressid
    												c053e4b8-48eb-4f47-8b61-107f87dd1635
    											
    											
    												donotbulkemail
    												************
    											
    											
    												modifiedby
    												
    													c23043eb-1466-4012-9781-6ce5675dc173
    													
    													systemuser
    													crm admin
    													
    												
    											
    											
    												new_donotphonebusinness
    												************
    											
    											
    												shippingmethodcode
    												
    													1
    												
    											
    											
    												createdby
    												
    													c23043eb-1466-4012-9781-6ce5675dc173
    													
    													systemuser
    													crm admin
    													
    												
    											
    											
    												new_donotphonesms
    												************
    											
    											
    												address1_city
    												************
    											
    											
    												donotbulkpostalmail
    												false
    											
    											
    												contactid
    												4f0ea3d9-8f34-e911-867a-0003ff4c4e0b
    											
    											
    												new_datacleansingscript
    												************
    											
    											
    												participatesinworkflow
    												************
    											
    											
    												statecode
    												
    													0
    												
    											
    											
    												owningbusinessunit
    												
    													7d6baed2-851b-e911-a960-000d3a29f363
    													
    													businessunit
    													
    													
    												
    											
    											
    												new_cust_id
    												************
    											
    											
    												address2_addressid
    												6e5b561d-7c82-41af-87cf-4ab680cfcc43
    											
    											
    												address1_postalcode
    												************
    											
    											
    												new_business2_original
    												************
    											
    											
    												telephone1
    												************
    											
    											
    												new_phone_businness_opt_in_date_time
    												************
    											
    											
    												new_donotphonebusinness_scope
    												************
    											
    											
    												new_email_opt_in_date_time
    												************
    											
    											
    												new_donotemail_scope
    												************
    											
    											
    												new_phone_home_opt_in_date_time
    												************
    											
    											
    												new_donotphonehome_scope
    												************
    											
    											
    												new_phone_opt_in_date_time
    												************
    											
    											
    												new_donotphone_scope
    												************
    											
    											
    												new_sms_opt_in_date_time
    												************
    											
    											
    												new_donotphonesms_scope
    												************
    											
    											
    												new_fax_opt_in_date_time
    												************
    											
    											
    												new_donotfax_scope
    												************
    											
    											
    												new_postal_mail_opt_in_date_time
    												************
    											
    											
    												new_donotpostalmail_scope
    												************
    											
    											
    												new_donotsharedata
    												************
    											
    											
    												new_data_forwarding_opt_in_date_time
    												************
    											
    											
    												new_donotsharedata_scope
    												************
    											
    										
    										Changed
    										
    											
    												customertypecode
    												Default Value
    											
    											
    												merged
    												No
    											
    											
    												new_donotphonehome
    												************
    											
    											
    												gendercode
    												************
    											
    											
    												territorycode
    												Default Value
    											
    											
    												haschildrencode
    												Default Value
    											
    											
    												preferredappointmenttimecode
    												************
    											
    											
    												new_record_shared
    												************
    											
    											
    												isbackofficecustomer
    												No
    											
    											
    												new_datacleanstatus
    												************
    											
    											
    												msdyn_orgchangestatus
    												No Feedback
    											
    											
    												donotpostalmail
    												************
    											
    											
    												marketingonly
    												No
    											
    											
    												donotphone
    												************
    											
    											
    												preferredcontactmethodcode
    												Any
    											
    											
    												educationcode
    												Default Value
    											
    											
    												ownerid
    												crm admin
    											
    											
    												customersizecode
    												Default Value
    											
    											
    												address2_addresstypecode
    												Default Value
    											
    											
    												donotemail
    												************
    											
    											
    												address2_shippingmethodcode
    												Default Value
    											
    											
    												msdyn_gdproptout
    												No
    											
    											
    												address2_freighttermscode
    												Default Value
    											
    											
    												statuscode
    												Active
    											
    											
    												createdon
    												2/19/2019 9:46 PM
    											
    											
    												new_parent_id
    												************
    											
    											
    												donotsendmm
    												Do Not Send
    											
    											
    												donotfax
    												Do Not Allow
    											
    											
    												new_share_record
    												************
    											
    											
    												leadsourcecode
    												Default Value
    											
    											
    												followemail
    												************
    											
    											
    												modifiedon
    												1/24/2020 1:27 PM
    											
    											
    												creditonhold
    												No
    											
    											
    												donotbulkemail
    												Do Not Allow
    											
    											
    												modifiedby
    												crm admin
    											
    											
    												new_donotphonebusinness
    												************
    											
    											
    												shippingmethodcode
    												Default Value
    											
    											
    												createdby
    												crm admin
    											
    											
    												new_donotphonesms
    												************
    											
    											
    												donotbulkpostalmail
    												No
    											
    											
    												new_datacleansingscript
    												************
    											
    											
    												participatesinworkflow
    												No
    											
    											
    												statecode
    												Active
    											
    										
    										4f0ea3d9-8f34-e911-867a-0003ff4c4e0b
    										
    										contact
    										
    										252500091
    									
    								
    								contact
    								
    								false
    								
    								0
    								false
    							
    						
    					
    					
    				
    			
    		
    		
    		Create
    	
    

    Response:

    	
    		http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/ExecuteOrganizationServiceFaultFault
    		urn:uuid:e534a976-b451-4e8f-a7bf-81082a58a4c4
    		00000000-0000-0000-0000-000000000000
    		
    			
    				2020-01-27T20:05:28.993Z
    				2020-01-27T20:10:28.993Z
    			
    		
    	
    	
    		
    			
    				s:Sender
    			
    			
    				A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
    			
    			
    				
    					b81c5ece-4945-4025-a4fb-82696798d75c
    					-2147088238
    					
    						
    							ApiExceptionSourceKey
    							Plugin/Microsoft.Crm.Common.ObjectModel.ContactService
    						
    						
    							ApiOriginalExceptionKey
    							Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again. ---> Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
    
       at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.ThrowDuplicateRecordException(IBusinessEntity entity, ExecutionContext context, SqlException e)
    
       at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.Update(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)
    
       at Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoUpdate(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)
    
       --- End of inner exception stack trace ---
    
       at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
    
       at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
    
       at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass3_0.b__0()
    						
    						
    							ApiStepKey
    							90750cb3-cfdc-db11-8341-0019b9204da9
    						
    						
    							ApiDepthKey
    							2
    						
    						
    							ApiActivityIdKey
    							b81c5ece-4945-4025-a4fb-82696798d75c
    						
    						
    							ApiPluginSolutionNameKey
    							System
    						
    						
    							ApiStepSolutionNameKey
    							System
    						
    						
    							ApiExceptionCategory
    							ClientError
    						
    						
    							ApiExceptionMesageName
    							DuplicateRecordEntityKey
    						
    						
    							ApiExceptionHttpStatusCode
    							412
    						
    						
    							DuplicateEntity
    							GOT REMOVED, CONTAINS THE EXISTING ENTITY FIELDS FROM THE CRM
    						
    						
    							DuplicateAttributes
    							existing.email@email.com
    						
    					
    					http://go.microsoft.com/fwlink/?LinkID=398563&error=Microsoft.Crm.CrmException:80060892&client=platform
    					A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
    					2020-01-27T20:05:28.9939507Z
    					false
    					
    					
    						b81c5ece-4945-4025-a4fb-82696798d75c
    						-2147088238
    						
    							
    								ApiExceptionSourceKey
    								Plugin/Microsoft.Crm.Common.ObjectModel.ContactService
    							
    							
    								ApiOriginalExceptionKey
    								Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again. ---> Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
    
       at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.ThrowDuplicateRecordException(IBusinessEntity entity, ExecutionContext context, SqlException e)
    
       at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.Update(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)
    
       at Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoUpdate(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)
    
       --- End of inner exception stack trace ---
    
       at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
    
       at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
    
       at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass3_0.b__0()
    							
    							
    								ApiStepKey
    								90750cb3-cfdc-db11-8341-0019b9204da9
    							
    							
    								ApiDepthKey
    								2
    							
    							
    								ApiActivityIdKey
    								b81c5ece-4945-4025-a4fb-82696798d75c
    							
    							
    								ApiPluginSolutionNameKey
    								System
    							
    							
    								ApiStepSolutionNameKey
    								System
    							
    							
    								ApiExceptionCategory
    								ClientError
    							
    							
    								ApiExceptionMesageName
    								DuplicateRecordEntityKey
    							
    							
    								ApiExceptionHttpStatusCode
    								412
    							
    						
    						
    						A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
    						2020-01-27T20:05:28.9939507Z
    						false
    						
    						
    							b81c5ece-4945-4025-a4fb-82696798d75c
    							-2147088238
    							
    								
    									ApiExceptionSourceKey
    									Plugin/Microsoft.Crm.Common.ObjectModel.ContactService
    								
    								
    									ApiOriginalExceptionKey
    									Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again. ---> Microsoft.Crm.CrmException: A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
    
       at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.ThrowDuplicateRecordException(IBusinessEntity entity, ExecutionContext context, SqlException e)
    
       at Microsoft.Crm.Platform.Server.DataEngine.EntityCrudManager.Update(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)
    
       at Microsoft.Crm.BusinessEntities.BusinessProcessObject.DoUpdate(IBusinessEntity entity, FilterExpression filter, ExecutionContext context)
    
       --- End of inner exception stack trace ---
    
       at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
    
       at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
    
       at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass3_0.b__0()
    								
    								
    									ApiStepKey
    									90750cb3-cfdc-db11-8341-0019b9204da9
    								
    								
    									ApiDepthKey
    									2
    								
    								
    									ApiActivityIdKey
    									b81c5ece-4945-4025-a4fb-82696798d75c
    								
    								
    									ApiPluginSolutionNameKey
    									System
    								
    								
    									ApiStepSolutionNameKey
    									System
    								
    								
    									ApiExceptionCategory
    									ClientError
    								
    								
    									ApiExceptionMesageName
    									DuplicateRecordEntityKey
    								
    								
    									ApiExceptionHttpStatusCode
    									412
    								
    							
    							
    							A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
    							2020-01-27T20:05:28.9939507Z
    							false
    							
    							
    								b81c5ece-4945-4025-a4fb-82696798d75c
    								-2147088238
    								
    								
    								A record that has the attribute values Email already exists. The entity key EmailAlternateKey requires that this set of attributes contains unique values. Select unique values and try again.
    								2020-01-27T20:05:28.9939507Z
    								false
    								
    								
    								
    								
    							
    							
    							
    						
    						
    						
    					
    					
    					
    				
    			
    		
    	
    

    Again, for some resason it seems like it tries to create an already existing Contact entity, and since we have an AlternateKey on the email address, it'll fail.

    Any ideas?

    Thanks for your answers!

  • RE: ServiceContext.SaveChanges() with Contact email unique key triggers CrmException

    To submit a support request, please go to admin.powerplatform.microsoft.com. Please, add the link of this forum thread into the support request.

  • RE: ServiceContext.SaveChanges() with Contact email unique key triggers CrmException

    Hi Attila, 

    Could you please confirm the CRM version ? Is it On premises or online deployment ?

    I would suggest to open a Support request to Microsoft for further investigation. Besides the CRM version, is it possible to share your C# code and confirm the details regarding the Entities relationship diagram ? Thanks in advance.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans