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

I am trying to change the value of the categories field in each contact in a public contacts folder in Outlook. I have the code below. It is not saving the new value? I'm sure I need to somehow save the value back but I can not figure out how to do that?
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 $Contacts = $NameSpace->Folders("Public Folders")->Folders("All Pub +lic Folders")->Folders("Test"); my $contact_items = $NameSpace->Folders("Public Folders")->Folders("Al +l Public Folders")->Folders("Test")->{Items}; my $it = $contact_items->GetFirst; #get the first item foreach my $item (in $Contacts->{Items}){ $it->{Categories} = "New Categories Value"; ## Code needed here to save the above new value? $it = $contact_items->GetNext; }
Any ideas how I can accomplish this?

Replies are listed 'Best First'.
Re: Changing Outlook Contact Items
by NetWallah (Canon) on Sep 20, 2006 at 04:40 UTC
    Your code mixes up "$it" and "$item". You had the right idea in the "foreach my $item (in $Contacts->{Items}){" - you should use $item inside that loop, and delete the $it->GetFirst/GetNext stuff.

    Anyway, once you get your contact item loaded into $item, you can :

    $item->{Categories} = 'Blue Category, This is another, This is one +category, and green category too'; # Note the syntax here requires curlies, to SET the property # You can omit the curlies when GETTING the properties, which I thi +nk is safer. #Eg: $Contacts->Items , instead of $Contacts->{Items} $item->Save; # This is the step you were looking for !

         "For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken

A reply falls below the community's threshold of quality. You may see it by logging in.