Modifying the Account form to hold visiting and postal address in MS Dynamics CRM 4.0

I was asked to modify the Accounts Form in Microsoft Dynamics CRM 4.0, to better match the company and Dutch way of working with addresses. Among others, I wanted to show both the visiting and postal addresses for a company in the same screen.

The Account Form already had some minor modifications; such as making the Primary Contact and Relationship Type recommended values. The Account also already shows a section ‘Address’ with it’s most important attributes. As there was no shipping to customers, attributes such as Shipping Method and Freight Terms could be left out.

The main problem with the current form was the fact that there is only one address on the form, while most accounts have (at least) two addresses that need to be recorded: it’s visiting and postal address (which can be the same, but often differ). One solution could be to use the “More Addresses” list, but these are ‘generic’ address entities that are linked to the account. What many don’t know is that an account has additional address fields which can hold this information.

Here’s how you go about altering the Account form:

rename address section

Go to SettingsCustomizationCustomize Entities, open th account entity and then open the main application form. Next, remove the unwanted attributes from the form and rearrange it.

rename address section

Rename the address section to Visiting Address.

add new sectionThen add a new section below the visiting address: Postal Address.

add fields to sectionSelect the fields from the Address2 collection that you want to use in the Postal Address, in my case these were the same fields as the visiting address.

rearrange fieldsThe fields will be added in the same order in which they are listed in the Add Fields dialog so they’ll have to be rearranged.

rearranged and renamed fieldsRearrange and rename the fields to suit your purpose.

Both addresses also have an Address Name attribute. This field is (often) used to display the organisation name when printing an address. I want it to be equal to the Account Name by default, but still allow the users to modify it to their exact needs. To make this easy, I implemented a client-side script that runs on the OnSave event for the
form:

// Retrieve the name of the account, if it is empty, then use an empty string
var lookupvalue = "";
if (crmForm.all.name.DataValue != null)
{
    lookupvalue = String(crmForm.all.name.DataValue);
}

// Fill the Visiting and Postal Address Name fields ('address1_name' and 'address2_name') if they are empty
if (crmForm.all.address1_name.DataValue == null || crmForm.all.address1_name.DataValue == "")
{
    crmForm.all.address1_name.DataValue = lookupvalue;
}

if (crmForm.all.address2_name.DataValue == null || crmForm.all.address2_name.DataValue == "")
{
    crmForm.all.address2_name.DataValue = lookupvalue;
}

OnSave event codeMake sure you enable the event.

Set dependencies

It’s also wise to set the dependencies for the script, so the fields cannot be removed.

Now when a user saves the form, the Address Name fields for the visiting and postal addresses will be filled with the (mandatory) Account Name field. The Address Name fields are not read-only, so users can override this setting. If they already did fill the fields, they will be left untouched.

In this case, CRM is also used in Dutch, so I’ll have to provide translations for the renamed and added form elements.

Dutch versionThis is what the form looks like in Dutch, before translating. Export Labels for Translation and open them in Excel or your favorite Xml editor.

Translating itemsTranslate the labels. The ones for the Address 2 fields will be empty initially.

End result in DutchAnd here’s the end result in Dutch. All that’s left now is to define the address types for Address 2 (and for the visiting address, if required).

Leave a Reply

Your email address will not be published. Required fields are marked *