Thursday, 3 January 2008

Populate the Company Name field on Contacts in Outlook 2003 from Microsoft CRM Outlook Client

Hi All,

You can set the Parent Account field on contacts in Microsoft Dynamics CRM, however the name of the Parent Account does NOT automatically populate the Company Name field on contacts in Microsoft Office Outlook 2003.

This article contains the steps that are required to create a custom macro in Outlook 2003 that will copy the name of the Parent Account from the Microsoft CRM contact to the Company Name field on the Outlook 2003 contact.

The macro runs when Outlook 2003 starts and then watches the contact list via event handlers for any additions and/or changes. There is also a manual version of the synchronisation that can be run if in case the synchronisation is out of time. When you run the manual synchronisation, the Company Name field will be populated for all the Outlook 2003 contacts associated to a Microsoft CRM contact.

For testing, you will need to lower the Outlook 2003 macro security settings by following the below instructions:

1. In Outlook 2003, click Tools, click Macro, and then click Security.
2. In the security window, mark Low.

Note: This setting is not recommended for standard use. However, the setting is required to enable the macro to run successfully. An alternative to running the macro in the Low security mode is to digitally sign the VBA code. As soon as the code is signed, you will be able to run the macro in a higher security mode.

3. Click OK to accept the security changes.
4. Close and then restart Microsoft Outlook to set the security mode.

Follow these steps to create the macro:

1. Open Outlook 2003.
2. Click Tools on the Microsoft Outlook Toolbar, point to Macro, and then click Visual Basic Editor.
3. In the Project Explorer, expand Project1, expand Microsoft Office Outlook Objects, and then double-click the ThisOutlookSession built-in module.
4. In the ThisOutlookSession Module, paste the following code into the code window:


Dim olApp As New Outlook.Application
Public WithEvents myContacts As Outlook.Items
Public blnAlert As Boolean

Public Sub CompanyName_Sync()
Dim objContact As ContactItem
Call Initialise_Handlers
For Each objContact In myContacts
Call SyncCompanyName(objContact)
Next
If blnAlert Then
MsgBox ("Synch Completed")
End If
End Sub

Private Sub Application_Startup()
Call Initialise_Handlers
blnAlert = False
Call CompanyName_Sync
blnAlert = True
End Sub

Private Sub myContacts_ItemChange(ByVal Item As Object)
Call SyncCompanyName(Item)
End Sub

Private Sub myContacts_ItemAdd(ByVal Item As Object)
Call SyncCompanyName(Item)
End Sub

Private Sub Initialise_Handlers()
Set myContacts = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Items
End Sub

Private Sub SyncCompanyName(ByRef Item As Object)
If Not Item.UserProperties.Item("Parent Account") Is Nothing Then
Dim strParentAcct As String, strCompanyName As String
strCompanyName = Item.CompanyName

strParentAcct = Item.UserProperties.Item("Parent Account")

If strParentAcct <> "" And Item.MessageClass = "IPM.Contact" And strCompanyName <> strParentAcct Then
Item.CompanyName = strParentAcct
Item.Save
Else
Exit Sub
End If
End If
End Sub

5. Save the Project and close the VBA editor.

Restart Outlook. Navigate to the contacts list and all the CRM contacts should now have the company name field populated with the Microsoft CRM parent account data.

New contacts added to the list will also have the company name field populated.
Any attempts to change the company name field will overwrite the changes and replace them with the Microsoft CRM parent account data.

This macro will only run, whenever you open the outlook. YOu can also manually run this macro by going to tools--> macros--> macros in outllook. Then macro name and ckick on Run.

2 comments:

Anonymous said...

However, season five may be the end.

my weblog; get my lover back

Anonymous said...

As a critical term, Art Deco is famously imprecise and never
more so than when applied to used cars for sale in albuquerque.
But despite of low prices of used used cars for sale in
albuquerque. You can therefore expect to see a fairly expensive price tag on these types of
lights and the relevant features of it. You can avail tax saving advantages or pick a plan that suits your
monthly expenditure. Nowadays, most used cars for sale in
albuquerque have fuel injection.

My web page; who buys used cars