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)

Getting Duplicate Record found in CustomerAddress Entity

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Daniel Wikell Profile Picture
    2,360 on at

    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.

  • CRM Beginner  Profile Picture
    795 on at

    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);

                               }

  • Verified answer
    Daniel Wikell Profile Picture
    2,360 on at

    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
    795 on at

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

  • Daniel Wikell Profile Picture
    2,360 on at

    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
    795 on at

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

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