in reply to Re: Perl control of Outlook import to contacts with win32::OLE
in thread Perl control of Outlook import to contacts with win32::OLE

Ok C - my testing goes well until I installed this subroutine in my cgi script:
sub OutLookAdd{ my ($id) = @_; my $sql = qq!select phones.id, phones.first_name, phones.last_name, phones.identifier, phones.prefix1, phones.suffix1, phones.prefix2, phones.suffix2, phones.site, phones.location, phone_location.title from phones, phone_location where phones.id = $id and phones.phone_location_id = phone_location.id!; $db_action = $DB->prepare($sql); $db_action->execute or die "Could not do $sql - $DBI::errstr"; my $rec = $db_action->fetchrow_hashref; $db_action->finish; my $OL = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application', 'Quit'); my $NameSpace = $OL->GetNameSpace("MAPI"); my $Contacts = $NameSpace->Folders("Mailbox - Norris, Joseph")->Folders("test_co +ntacts"); $rec->{title} =~ s/\\//g; my $NewContact = $Contacts->Items->Add(); $NewContact->{FullName}= $rec->{first_name} . ' ' . $rec->{las +t_name}; $NewContact->{Title} = $rec->{title}; $NewContact->{FirstName} = $rec->{first_name}; $NewContact->{MiddleName} = '1'; $NewContact->{LastName} = $rec->{last_name}; $NewContact->{Suffix} = '2'; $NewContact->{Company} = $rec->{title}; $NewContact->{Department} = '3'; $NewContact->{JobTitle} = '4'; $NewContact->{BusinessStreet} = '5'; $NewContact->{BusinessStreet2} = '6'; $NewContact->{BusinessStreet3} = '7'; $NewContact->{BusinessCity} = '8'; $NewContact->{BusinessState} = '9'; $NewContact->{BusinessPostalCode} = '10'; $NewContact->{BusinessCountry} = '11'; $NewContact->{HomeStreet} = '12'; $NewContact->{HomeStreet2} = '13'; $NewContact->{HomeStreet3} = '14'; $NewContact->{HomeCity} = '15'; $NewContact->{HomeState} = '16'; $NewContact->{HomePostalCode} = '17'; $NewContact->{HomeCountry} = '18'; $NewContact->{OtherStreet} = '19'; $NewContact->{OtherStreet2} = '20'; $NewContact->{OtherStreet3} = '21'; $NewContact->{OtherCity} = '22'; $NewContact->{OtherState} = '23'; $NewContact->{OtherPostalCode} = '24'; $NewContact->{OtherCountry} = '25'; $NewContact->{BusinessFax} = '26'; $NewContact->{BusinessPhone} = join '-', $rec->{prefix1}, $rec->{suffix1}; if ($rec->{prefix2}){ $NewContact->{BusinessPhone2} = join '-', $rec->{prefix2}, $rec->{suffix2}; } else { $NewContact->{BusinessPhone2} = '27'; } $NewContact->{Callback} = '28'; $NewContact->{CarPhone} = '29'; $NewContact->{CompanyMainPhone} = '30'; $NewContact->{HomeFax} = '31'; $NewContact->{HomePhone} = '32'; $NewContact->{HomePhone2} = '33'; $NewContact->{ISDN} = '34'; $NewContact->{MobilePhone} = '35'; $NewContact->{OtherFax} = '36'; $NewContact->{OtherPhone} = '37'; $NewContact->{Pager} = '38'; $NewContact->{PrimaryPhone} = join '-', $rec->{prefix1}, $rec->{suffix1}; $NewContact->{RadioPhone} = '39'; $NewContact->{Telex} = '40'; $NewContact->{Account} = '41'; $NewContact->{Anniversary} = '42'; $NewContact->{BillingInformation} = '43'; $NewContact->{Birthday} = '44'; $NewContact->{Categories} = '45'; $NewContact->{Children} = '46'; $NewContact->{DirectoryServer} = '47'; $NewContact->{"E-mail Address"} = 'mytest@mytest.com'; $NewContact->{"E-mail Type"} = '48'; $NewContact->{"E-mail Display Name"} = '49'; $NewContact->{"E-mail2 Address"} ='50'; $NewContact->{"E-mail2 Type"} = '51'; $NewContact->{"E-mail2 Display Name"} = '52'; $NewContact->{"E-mail3 Address"} = '53'; $NewContact->{"E-mail3 Type"} = '54'; $NewContact->{"E-mail3 Display Name"} = '55'; $NewContact->{Gender} = '56'; $NewContact->{GovernmentIDNumber} = '57'; $NewContact->{Hobby} = '58'; $NewContact->{Location} = $rec->{location}; $NewContact->{User1} = $rec->{site}; $NewContact->Save(); }
When I run the cgi I get an update to my database and then a return of information but when the ole stuff gets invoked I get:
Win32::OLE(0.1502) error 0x80080005: "Server execution failed" at c:\w +eb\cgi-bin\PHONEL~1\new.pl line 209 eval {...} called at c:\web\cgi-bin\PHONEL~1\new.pl line 209 main::OutLookAdd(407) called at c:\web\cgi-bin\PHONEL~1\new.pl lin +e 183 main::additem2 called at c:\web\cgi-bin\PHONEL~1\new.pl line 84
Any idea what I am doing wrong? Thanks.

Replies are listed 'Best First'.
Re: Check your property Names in the Outlook ContactItem Class
by cacharbe (Curate) on May 24, 2002 at 12:15 UTC
    I can tell you right off the top that a bunch of your property names are incorrect. Here is what the property names should be (I've only included the ones to which you were actually giving data):
    $NewContact->{FullName}= $rec->{first_name} . ' ' . $rec->{last_name}; $NewContact->{Title} = $rec->{title}; $NewContact->{FirstName} = $rec->{first_name}; $NewContact->{LastName} = $rec->{last_name}; $NewContact->{BusinessTelephoneNumber} = join '-', $rec->{prefix1}, $rec->{suffix1}; if ($rec->{prefix2}){ $NewContact->{Business2TelephoneNumber} = join '-', $rec->{prefix2}, $rec->{suffix2}; } else { $NewContact->{Business2TelephoneNumber} = '27'; } $NewContact->{CompanyName} = $rec->{company}; $NewContact->{PrimaryTelephoneNumber} = join '-', $rec->{prefix1}, $rec->{suffix1}; $NewContact->{OfficeLocation} = $rec->{location}; $NewContact->{User1} = $rec->{site}; $NewContact->{"Email1Address"} = 'mytest@mytest.com';
    See if that helps. Use that browser that I pointed out to actually investigate the 'ContactItem' class object, and use the exact name given for the other properties in question.

    C-.

    Update: To answer your other questions. You should read the Win32::OLE documentation first. The GetActiveObject method is described there, as it's a part of that package.

      Oh wise C, I wish to thank you for this help. You have given me the tools to finish a very important project. Thanks again.
        Null Perspiration.

        cacharbe's the name, Win32:OLE is my game.

        C-.