Calling the Outlook Address Book from InfoPath
Ok, so I'm no code slinger, but once in a while I get my hands dirty and write (more like customize existing) code. Many times I have to break the bad news to customers that Outlook as a forms tool linking to Public Folders is going the way of the dodo. Therefore I get requests on how to convert Outlook forms to InfoPath. Most stuff is easy, but the stuff that involves e-mail functions and integration with Exchange are not as developed, and often require code. I asked internally at Microsoft on how to call into the Global Address Book in Exchange and pull back info into InfoPath, and got only one response. Here is an excerpt from the mail I sent back to the internal alias after I got it working.
Wanted to add a little back to the alias here with some follow-on work I did on automating the Outlook Address Book from InfoPath. Specifically, the code snippet below invokes the Outlook Address Book, allows a user to pick a single person from the GAL, and then puts that user’s alias into a field in the form. Sounds easy, but isn’t. Zoltan Pekic deserves most of the credit for his starter code, but I found it much more complex than what I actually needed, and thus wanted to drop this simpler snippet onto the alias for future posterity. The button on the form invokes the Access_GAL function. I used a SQL backend to my form, so the structure of the node path will likely be much simpler if not using a SQL backend. It’s all in jscript, everyone favorite dev environment (not!). Enjoy.
var g_oMapiSession = null;
g_oMapiSession = new ActiveXObject("MAPI.Session");
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of arguments.
var oRecipients = null;
//var oTestMessage=EnsureValue(g_oMapiSession.Outbox.Messages.Add(),'Cannot create test message');
oRecipients=g_oMapiSession.AddressBook(oTestMessage.Recipients, "Managers", true, true, 1, "Add");
var nameApprovingManager = XDocument.DOM.selectSingleNode("dfs:myFields/dfs:dataFields/d:Detail/@Approving_Mgr");
var nameLength = String(nameApprovingManager.text).length;
var equalPosition = FindTheEqual(nameApprovingManager.text);
nameApprovingManager.text = String(nameApprovingManager.text).substring(equalPosition, nameLength);
for (i=String(strSearch).length; i >0; i--)
if (strSearch.substring(i-1,i)== "=")