Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have the code below which will successfully accesses and print the standard contact fields in a given Outlook contact folder that uses the standard contact form. The given code happens to access a public contacts folder, but results are the same for a privite contact folder. The problems is that I have created a custom contact form and the code below will not access any of the custom fields (the test fields below). It accesses the standard fields just fine. I have tried creating the custom fields in different ways and nothing seems to work. Ideas?
use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Outlook'; $|++; $Win32::OLE::Warn = 3; # Die on errors my $OL = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application', 'Quit'); my $NameSpace = $OL->GetNameSpace("MAPI"); my $folder="TestFolder"; my $Contacts = $NameSpace->Folders("Public Folders")->Folders("All Pub +lic Folders")->Folders("Corporate Contacts")->Folders($folder); my $contact_items = $NameSpace->Folders("Public Folders")->Folders("Al +l Public Folders")->Folders("Corporate Contacts")->Folders($folder)-> +{Items}; foreach my $item (in $Contacts->{Items}){ print "Category: $item->{Categories}\n"; print "Company: $item->{CompanyName}\n"; print "Test Field 1: $item->{Test}\n"; print "Test Field 2: $item->{Test2}\n"; print "Test Field 3: $item->{Test3}\n"; print "Test Field 4: $item->{Test4}\n"; print " File As: $item->{FileAs}\n\n"; } print "Done!\n";

Replies are listed 'Best First'.
Re: Accessing a user defined field in an Outlook Contact
by traveler (Parson) on Oct 02, 2006 at 22:33 UTC
    I think for your custom fields you need something like
    print "Test Field 4: $item->UserProperties(Test4)\n";
    (but I have no easy way to test it here).
      That seems to be very close, but not quite there. I get the following output:

      Test Field 4: Win32::OLE=HASH(0x1974e98)->UserProperties{Test4}

      How do I get to the actual value?
        In my post I have UserProperties followed by parens because it is a function. Your error shows curly braces. Did you use parens?

        You could also use Data::Dumper to print the $item hash.

        HTH