in reply to Re: Re: Re: Check your property Names in the Outlook ContactItem Class
in thread Perl control of Outlook import to contacts with win32::OLE

C, Here I am bothering you again. I have had much success thanks to your instruction. I have been very successful in finding and deleting items from contacts folder. Here is my question: I have the following snipet:
my $NewContact = $Contacts->Items->find("[Last Name] = $name"); print "full name: $NewContact->{FullName}\n"; print "First name: $NewContact->{FirstName}\n"; print "Last name: $NewContact->{LastName}\n"; print "Phone: $NewContact->{BusinessTelephoneNumber}\n"; print "Title: $NewContact->{CompanyName}\n"; $NewContact->Delete();
Now there may be a bunch of Smiths and I don't want to trash all of them - How can I do this same thing by index. The whole index deal leaves me a little lost - how do I return and index to script? Thanks
  • Comment on Re: Re: Re: Re: Check your property Names in the Outlook ContactItem Class
  • Download Code

Replies are listed 'Best First'.
Re:(4)What do you want to delete?
by cacharbe (Curate) on May 29, 2002 at 19:58 UTC
    I would look at the parameters on which you DO want to delete, and work it something like this. (Based on the following)
    use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Outlook'; $|++; $Win32::OLE::Warn = 3; # Throw Errors, I'll catch them my $OL = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application', 'Quit'); my $NameSpace = $OL->GetNameSpace("MAPI");

    I used this to fill in some values:

    my $Contacts = $NameSpace->Folders("Personal Folders")->Folders("Cont +acts"); my @names = qw(Chuck Charles Charlie Chuckles); foreach my $name (@names){ my $NewContact = $Contacts->Items->Add(); $NewContact->{FirstName}=$name; $NewContact->{LastName}="Charbeneau"; $NewContact->Save(); print "Added $name\n"; }

    And this to delete the names I don't like:

    $Contacts = $NameSpace->Folders("Personal Folders")->Folders("Contact +s")->{Items}; my $Cacharbes = $Contacts->Find("[LastName]=Charbeneau"); my $cnt = 0; while (1) { if ($Cacharbes->{FirstName} eq "Chuckles"){ $Cacharbes->Delete(); } $Cacharbes = $Contacts->FindNext() || last; }

    The thing is, the find and find next function only return a single item from the main collection.

    Each item in a Contacts folder collection has a unique ->{EntryID} property, but it's not something you can remmber off the top of your head.

    C-.

      This is very good - however what happens if Charbeneau does not exist in the contacts file. Can I do some sort of Last Name = C* to get to the beginning of the C's and then FindNext or how the the error condition be handled if there is not match. What I am attempting to do is allow my cgi to update this contacts file from our intranet. Thanks.
        I would replace the complete last name with this:
        my $Cacharbes = $Contacts->Find("[LastName]>C and[LastName]<D ");

        C-.