Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 13977

Change Primary Address of Account/Contact records in Microsoft Dynamics CRM

$
0
0

Introduction

In CRM, an account or a contact can have more than 1 addresses out of which primary address is shown on Account/Contact form in address fields. This blog explains how can we set any other address as a primary address and show on the form.

Requirement:

An account can have more than 1 addresses which are shown under more addresses tab of an account record. The Primary Address is always shown on Account form and it is not shown under More Addresses section.

more address section

address on account form

User has customized address entity and added a checkbox field on Address form to decide whether the address is primary address or not. Now when user sets this field as True, the address should become primary address on account/contact form and existing primary address should be shown under more addresses section.

How addresses are stored in CRM?

  1. Addresses in CRM are stored in Address entity.
  2. Address entity has unique identifier field as Address Number for each of the parent record i.e. either Account or contact.
  3. Whenever an account or contact is created in CRM, by default 2 address records are created in Address entity for the respective account or contact record. Address Number of the primary address is always set as 1.
  4. For one account or contact, address number field cannot contain duplicate values.

Solution to the requirement

As primary address is identified with the help of Address Number field, i.e. when Address Number is set as 1, it becomes primary address. Hence, when user sets the checkbox to YES, we just have to change the address number field to 1 to make that address as a primary address. On main form of account or contact, details of address will be shown where account number is 1.

Catch in the solution: As already said above, for one account or contact, address number field cannot contain duplicate values, hence if we directly try to set address number field to 1, it will throw an error saying duplicate record found. Below is the solution to this problem.

Deploy a plugin on update of ‘Is Primary’ field on Address entity
We will see the solution with the help of below example:
 
Assume we have A. Datum account with 5 addresses.

Account NameAddress NumberIs Primary?
A. Datum1YES
 2 
 3 
 4 
 5 

Now, User updates ‘Is Primary’ Field of Address 5 as YES. Below is the data update done by User.

Account NameAddress NumberIs Primary?
A. Datum1YES
 2 
 3 
 4 
 5YES

Below data operations should be performed in Plugin.

Step 1:

Account NameAddress NumberIs Primary?
A. Datum1YES
 2 
 3 
 4 
 0YES

Step 2:

Account NameAddress NumberIs Primary?
A. Datum5NO
 2 
 3 
 4 
 0YES

Step 3:

Account NameAddress NumberIs Primary?
A. Datum5NO
 2 
 3 
 4 
 1YES

 

The post Change Primary Address of Account/Contact records in Microsoft Dynamics CRM appeared first on CloudFronts - Microsoft CRM | AX | BI | Azure.


Viewing all articles
Browse latest Browse all 13977

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>