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

I was wondering if anyone out there has successfully queried a Lotus Notes database using perl(preferably from a linux workstation)? If so, how was it achieved?

Replies are listed 'Best First'.
RE: Accessing a Lotus Notes Database
by vroom (His Eminence) on May 02, 2000 at 18:11 UTC
    You might want to check out getnotes.pl it was posted here last week some time. I don't know how useful it is but it's probably worth checking out.

    vroom | Tim Vroom | vroom@cs.hope.edu
      scoombs and vroom,
      The getnotes.pl program is a very simple client for notes. I connected to Lotus notes 4.5 and I wrote the program about a year ago so it may not work properly anymore. I don't have lotus notes at my new company. :( I would appreciate it if you would try it so I can see if it still works. If you let me know what problems you are having or what you would like to see the program do post back I would be happy to help.

      Its kind of frustrating that the getnotes.pl program took me about two weeks to write and IMHO is way more interesting than the ebay pager program, which has about 3 time the reputation points and took two seconds to write.
Re: Accessing a Lotus Notes Database
by BBQ (Curate) on May 03, 2000 at 02:58 UTC
    If I had to come up with a quick-n-dirty solution for your case, I'd probably forget Linux for now and go with ODBC, ActiveState Perl on Win32, and DBD::ODBC...

    Before anyone kills me for saying this, I'll explain:
    I checked through CPAN, I noticed that the only mention of a LotusNotes interface was listed as an idea which means there is no available code. Tough break there...

    Therefor, it seems that the only imediate solution would be setting up a Win32 server (which I know for a FACT has an Lotus ODBC driver), install ActiveState's distro, install DBI and DBD::ODBC via PPM and you're off! Just don't expect the machine to perform well under stress, after all you will be:
    1. On a Windows machine.
    2. Using ODBC
    3. Loading DBD::ODBC as the 3rd layer

    There might be a way of doing this via Linux and ODBC as well, but I can't help you there since I have absolutely no idea if there is a Lotus client for Linux and/or ODBC support.
    I hope this helps as an alternative...

    #!/home/bbq/bin/perl
    # Trust no1!
      If there is a Lotus Notes ODBC client library for Linux, just use DBD::ODBC. If you can't get the ODBC library for Linux but can get it for another platform and still want to run your script on Linux, you should look at DBD::Proxy/DBI::ProxyServer. In a DBD::Proxy setup you would set up a DBI::ProxyServer process running on the box w/ the ODBC client library and it would connect to the Notes database. Then you use DBD::Proxy in your client program (running anywhere) to connect to the DBI::ProxySerer process. I know thats a lot of layers, but it does actually work. I've used this technique to connect a program on a Linux box to an MS-Access DB ... its more stable than you might think.
        Talk about n-tier!!
        Linux Wkst.        Windoze Server
        --------------    ------------------------------
        |Linux| DBD  |    | DBI  | DBD | ODBC  | Lotus |
        |Apps | Proxy|--->| Proxy| ODBC| Driver| Client|
        --------------    ------------------------------
                                                    |
          -------------                             |
          |Lotus Notes| <----------------------------
          |Server     |
          -------------
           AIX RS/6000
        
        Is this what you're talking about?
Re: Accessing a Lotus Notes Database
by Anonymous Monk on Dec 30, 2002 at 20:46 UTC
    Hi,

    I am trying to write a script that will take a name off the command line and return the internet email address as stored in the company global address book in Lotus Notes. The following script will loop through all records and print out the data, which I can redirect to a temp file for grep'ing later, but I would like to look it up realtime. I saw the @dblookup function in Lotus, but wasn't successful at running it via perl. Any ideas? Your help is greatly appreciated.

    use strict;
    use English;
    use warnings;
    use vars qw($opt_d $opt_v);
    use Getopt::Std;
    use Win32::OLE;
    
    # Open the email database in Lotus Notes
    # (To use another person's email database, switch to
    #  their userid in Notes before running this program)
    my $notes = Win32::OLE->new('Notes.NotesSession')
                 or die "Can't open Lotus Notes";
    my $database = $notes->GetDatabase("LNSERVER","names.nsf");
    #my $database = $notes->GetDatabase("","names.nsf");
    
    # Verify the server connection
    print "Connected to ", $database->{Title}, 
          " on ", $database->{Server}, "\n";
    
    # Loop over all of the folders
    foreach my $viewname (GetViews($database)) {
    
      # Get the object for this View
      print "Checking folder $viewname...\n";
      my $view = $database->GetView($viewname);
    
      # Get the first document in the folder
      my $num = 1;
      my $doc = $view->GetFirstDocument;
      next unless $doc;
      GetInfo($num,  $doc);
    
      # Get the remaining documents in the folder
      while ($doc = $view->GetNextDocument($doc)) {
        $num++;
        GetInfo($num, $doc);
      }
    }
    
    sub GetInfo
    {
      my ($num, $doc) = @_;
    
      my $FirstName = $doc->{'FirstName'}->[0];
      my $LastName = $doc->{'LastName'}->[0];
      my $MiddleInitial = $doc->{'MiddleInitial'}->[0];
      my $email = $doc->{'ShortName'}->[0];
      $email .= '@uhc.com';
      print "$FirstName $MiddleInitial $LastName\t$email\n";
    }
    
    sub GetViews {
       return ("People");
    }
    

      @DbLookup is not valid outside of the Notes client context and cannot be accessed via this method. Tough beans. Normally you follow a pattern something like the following when you're looking for something conceptually like @DbLookup. I'm posting this in LotusScript and you'll have to translate that into perl. I haven't use the OLE interface to perl so I don't want to just "wing" it.

      If you follow that it's just (a) get the view, (b) find document(s) that match your criteria, (c) do something with them. Easy peasy.

      If you need something faster/better then either (a) write an interface to the C or C++ API DominoPerl, (b) use the Java API (which works nicely) or (c) don't do it.

      Const C_VIEW = "People" Const C_KEY = "Marvin Martian/IT/SomeCompany" Const C_ITEM = "Fullname" Dim S As NotesSession Dim Db As NotesDatabase Dim View As NotesView Dim Doc As NotesDocument Set S = New NotesSession Set Db = S.CurrentDatabase Set View = Db.GetView( C_VIEW ) Set Doc = View.GetDocumentByKey( C_KEY, True ) If Doc.HasItem( C_ITEM ) Then Print C_ITEM & ": " & Doc.GetFirstItem( C_ITEM ).Text Else Print C_ITEM & " Doesn't exist!" End If

      Equivalent OLE code *might* look like this but you'll need to try it out for your self. In general you'll need to check out the LotusScript object model to see what is available.

      use constant C_VIEW => "People"; use constant C_KEY => "Marvin Martian/IT/SomeCompany"; use constant C_ITEM => "Fullname"; use strict; use warnings; use Win32::OLE; my $notes = Win32::OLE->new('Notes.NotesSession') or die "Can't open Lotus Notes"; my $db = $notes->GetDatabase(@{&C_DB()}); die "Database was not opened" unless $db->IsOpen; my $view = $db->GetView( C_VIEW ); my $doc = $view->GetDocumentByKey( C_KEY, -1 ); if (defined $doc) { print C_ITEM . ": " . $doc->GetFirstItem( C_ITEM )->Text() . "\n" +; } else { print C_ITEM . " Doesn't exist!\n" }

      Fun Fun Fun in the Fluffy Chair