Thursday, April 12, 2007

Public Folder Outlook Custom Form

Client Specific names have been changed.
I had a client service call come up in which individuals in the field were not getting all the contact information from an Outlook Public Folder Contact List when they synchronized the information with their phone/PDA.
Now I haven’t had to code and/or manage Outlook for a few years and I am not one to reinvent the wheel.
First thing was to look at the information from the Outlook Public Folder Contact List and from the PDA. The Contact List was managed through a custom form “OurContactForm” which had within it a custom field for collecting direct dial numbers (DDN). This field was not downloading to the mobile devices because there was no code behind to do so and all they were getting was the default IMP.Contact.Item fields.
Just a bit further research reviled that the “OurContactForm” form was originally created by a sales person and had initially contained a myriad of custom fields which had over time been systematically replaced with default contact item fields.
Side Note:
Anyone who has worked with Sales and/or Marketing departments staff will be familiar with this type of scenario. Why is that? I have never had a department except Sales and/or Marketing who will just start using a “Jerry did this” product/process as production without talking to anyone else in the company. Even in this case a five minute conversation like “hey, I have been thinking of utilizing custom forms to help get a unified presentation of our contacts. I will build it out in my copious free time.” And a reply of, “Great, be sure to use default custom values first just as a best practice, I would be happy to review your work or provide any guidance.” would have saved this company some hundred hours in modifications (without a basic knowledge of VBScript every change to a default item field was accompanied by data entry copy/paste).

I found previous bits and pieces of code from past “programmer/developer” staff members who had started putting together code to copy the DDN custom field data to the default IMP.Contact.Item.BusinessTelephoneNumber field “Business Phone” (BTN), but for whatever reason had never finished any of the various iterations of the code successfully.
The simplest solution to this issue then appeared to be to take the following steps.
1. Build a custom form “CopyDdn2Btn” with vbscript code in the Item_Open function to copy the “DDN” field value to the “BTN” field value.
a. An amendment to this code included assigning the custom form “OurContactForm” to the item after they where modified. Otherwise each item would try to open using the “CopyDdn2Btn” form
2. Alter the existing custom form “OurContactForm” to utilize the “Business Phone” field rather then the custom “Direct Dial” field
3. Alter the Public Folder default views replacing “Direct Dial” with “Business Phone”

Of course, the first step in this little scenario is to ensure I have ownership on the public folder in questions “OurContactNumbers”. Once that is accomplished, I copy the folder to a public folder subdirectory for testing and development.
Next I create the form “CopyDdn2Btn” from the “OurContactForm” and add “Business Phone” (IMP.Contact.Item.BusinessTelephoneNumber) to it and the following code.
=============
' VBScript source code
' Open Form Copy at item level Direct Dial to Business Phone
' Modified By James Andrew Malone 4/10 & 4/11 2007 Office Outlook 2003
Sub Item_Open

Dim objFolder ' As MAPIFolder
Dim objItems ' As Items
Dim objItem ' As Object

' Change the following line to your new Message Class
NewMC = "IPM.Contact.OurContactForm"

' Set objFolder to the current folder
set objFolder = Application.ActiveExplorer.CurrentFolder

If Not objFolder Is Nothing Then
' Set objItems to the current folder items
set objItems = objFolder.Items

' Loop through all of the items in the folder
For Each objItem In objItems
' make sure you have a Contact item

If objItem.Class = 40 Then ' Class = 40 = olContact
' convert to your published custom form
objItem.MessageClass = "IPM.Contact.CopyDdn2Btn"

strDDN = cstr( objItem.UserProperties("Direct Dial") )
strFullName = cstr( objItem.FullName )
strBTN = cstr( objItem.BusinessTelephoneNumber )

if strDDN <> "" then
if strDDN <> strBTN then
' MsgBox "Before!: " & strFullName &_
' " BTN: " & strBTN &_
' " DDN: " & strDDN

objItem.BusinessTelephoneNumber = strDDN
' Save the changed item
objItem.Save

' msgbox "After: " & cstr(CurItem.FullName) &_
' " BTN: " & cstr(CurItem.BusinessTelephoneNumber) ' &_
' " DDN: " & cstr( objItem.UserProperties("Direct Dial") )

End if ' if strDDN <> strBTN
End if ' if strDDN <> ""
' Test to see if the Message Class needs to be changed
If objItem.MessageClass <> NewMC Then

' Change the Message Class
objItem.MessageClass = NewMC

' Save the changed item
objItem.Save

End If
Else
MsgBox "objItem Class = " & cstr( objItem.Class ) ' exit sub
End if ' If objItem.Class = olContact

Next ' For Each objItem In objItems
Else
MsgBox "objFolder Is Nothing!"
End if ' If Not objFolder Is Nothing
Set objItems = Nothing
Set objItem = Nothing
Set objFolder = Nothing
MsgBox "Done."
End Sub
=============

I then publish this form in my test contact folder
Next I alter the “OurContactForm” changing the “Direct Dial” text box property to “Business Phone”. I also increased the version of the form and published it to my test contact folder.
Run the code:
• Select the public folder in the navigation bar
• From the Outlook menu browse through Tools > Forms > Choose Forms
• Browse to the test folder
• Select the “CopyDdn2Btn”
• Choose Open.
The form churns through the contact items and makes the changes. When the task is complete a “Done.” message pops up. Click “OK” and close the form. If prompted to save click “No” – this is asking about saving a blank contact item which was created when this custom form was successfully opened.
The public folder already had “OurContactForm” as its default form.
• Right click the public folder in the navigation bar; select properties; “When posting to this folder use:” should be set to “OurContactForm”. This only affects new items, existing items where associated with the form in the code.
The public folder views need modified and published
• From the Outlook menu browse through View > Arrange By > Current View > Define Views
• Make the changes to each public folder specific view
o Select the view
o Click Modify
o Make changes
o Click “OK”
• publish the changes
o Select the view
o Click “Publish”

Once users reviewed the test public folder, I publish the new “OurContactForm” in the production public folder and I execute the “CopyDdn2Btn”
Then publish the view changes to the production public folder

Resources:

Tutorial: Creating and distributing custom forms with Outlook By Debra Littlejohn Shinder, MCSE, MVP.

Publish a public folder view

OL2002: How to Update Existing Items to Use a New Custom Form

DevGuru VBScript Index

Microsoft Outlook Programming By Sue Mosher

Microsoft Outlook Custom Forms

To convert imported data to custom fields

No comments: