Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Getting Duplicate Record found in CustomerAddress Entity

Posted on by 795

Hi,

My requirement is to update address's parentid to point to other contactid..But when i am trying to update that particular address record, i am getting the error:  "Duplicate record foun for the particular customeraddressid".. But how it can be possible? As we always have a  unique customerid for each address record. 

Can anyone please help me out by giving suggestions?

Thanks

*This post is locked for comments

  • CRM Beginner  Profile Picture
    CRM Beginner 795 on at
    RE: Getting Duplicate Record found in CustomerAddress Entity

    Ok.. Thank you.. I will look at it

  • Daniel Wikell Profile Picture
    Daniel Wikell 2,360 on at
    RE: Getting Duplicate Record found in CustomerAddress Entity

    Depending on what the current state of Contact B is you have multiple options to consider.

    If Contact B currently has no data in address 1 and/or address 2 (the first two address objects always exists by default, but might be empty in data) then you want to send an Update request on Contact B and set the corresponding address-fields.

    If Contact B already has an address in 1 or 2 that you want to keep, you instead need to create new address objects out of the addresses in Contact A. You can modify your loop to simply create a new object, assign the same data and issue a Create request. This way you let CRM handle the assignment of the new address numbers (if Contact B already had address #3 for instance, CRM would then create a copy of address#1 from Contact A as Address #4 in Contact B and so on)

  • CRM Beginner  Profile Picture
    CRM Beginner 795 on at
    RE: Getting Duplicate Record found in CustomerAddress Entity

    So, you are absolutely right .. Can you suggest what can i do for it if i want to achieve the scenario ?

  • Verified answer
    Daniel Wikell Profile Picture
    Daniel Wikell 2,360 on at
    RE: Getting Duplicate Record found in CustomerAddress Entity

    Right so, it seems you are indeed trying to transfer all address records which will not work.

    Each address record has an address number (stored in the field 'addressnumber') which contains a number that starts with 1 and goes up for each new address record that is added to a contact.

    The address number is unique within the same Contact which means that one Contact cannot have more than one address record with address number 1 and so on.

    This means we could have the following scenario:

    Contact A (inactive)

    - Address #1

    - Address #2

    - Address #3

    - Address #4

    Contact B (Active)

    - Address #1

    - Address #2

    If you try to move all addresses of Contact A to belong to Contact B instead, then CRM will reject your request since you are trying to make Contact B have multiple Address #1 and Address #2 entries connected to it.

  • CRM Beginner  Profile Picture
    CRM Beginner 795 on at
    RE: Getting Duplicate Record found in CustomerAddress Entity

    Hey, i didn't get you.. Let me tell step by step:

    What i want is to update parentid of some inactive contacts to one of active contacts. For which, i retrieved inactive contacts and accessed the address records corresponding to each inactive contact and simply updating its parent id.. Let me show you the code snippet:

    public void GetAddresses(IOrganizationService service, EntityCollection response, string conString, Guid goldenCustomerID)

           {

               DataCollection<Entity> addresses = null;

               if (response.Entities != null && response.Entities.Count > 0)

               {

                   foreach (var item in response.Entities)

                   {

                       QueryExpression query = new QueryExpression { EntityName = "customeraddress", ColumnSet = new ColumnSet("customeraddressid", "parentid", "line1") };

                       query.Criteria.AddCondition("parentid", ConditionOperator.Equal, item.Attributes["contactid"]);

                       query.Criteria.AddCondition("line1", ConditionOperator.NotNull);

                       addresses = service.RetrieveMultiple(query).Entities;

                       if (addresses != null && addresses.Count > 0)

                       {

                          // BulkUpdate(service, addresses, goldenCustomerID, attributeName);

                           foreach(var addr in addresses)

                           {

                               addr.Attributes["parentid"] = new EntityReference("contact", goldenCustomerID);

                               try

                               {

                                   UpdateRequest reqUpdate = new UpdateRequest();

                                   reqUpdate.Target = addr;

                                   reqUpdate["SuppressDuplicateDetection"] = true; // Duplicate detection is activated.

                                   // Update the address record.

                                   UpdateResponse updateResponse = (UpdateResponse)service.Execute(reqUpdate);  // Error: Duplicate record found for Entity 1071 with ID: "someID "

                               }

                               catch (FaultException<OrganizationServiceFault> ex)

                               {

                                   Console.WriteLine(ex.Message);

                               }

  • Suggested answer
    Daniel Wikell Profile Picture
    Daniel Wikell 2,360 on at
    RE: Getting Duplicate Record found in CustomerAddress Entity

    Hi

    Are you attempting to move address with address number 3 and above or are you trying to move address number 1-2? If the latter, then it won't work that way since contacts can't have multiple addresses with the same address number. They automatically have address objects for address 1 and 2 and if you want to move any of these you will instead have to set the address fields directly on the contact instead.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans