Solved

Writing to address book via java agent

Posted on 2000-04-22
9
274 Views
Last Modified: 2013-12-18
I would be eternally grateful if there's someone out there who knows how to  WRITE to an address book database 'names.nsf' or write to database full stop.
0
Comment
Question by:badtzmaru
  • 3
  • 3
  • 2
  • +1
9 Comments
 

Expert Comment

by:sduncan99
ID: 2742539
Can you give more details on what you are trying to do and what version of the server you are running
0
 

Author Comment

by:badtzmaru
ID: 2742546
lotus domino 5

i am trying to extract a value from a notes address book(for eg. FirstName) to be used with a java agent.

also i would be needing to write a value to the adderss book too
0
 

Author Comment

by:badtzmaru
ID: 2742558
actually.. the whole point of me trying this is to import & export vCards to/from the address book
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Expert Comment

by:sduncan99
ID: 2742564
Can I ask why you are doing it with Java?
0
 

Expert Comment

by:sduncan99
ID: 2742567
Can I ask why you are doing it with Java?
0
 

Author Comment

by:badtzmaru
ID: 2742569
its for a university assignment.... i have to use object oriented java.
0
 

Expert Comment

by:Scott2000
ID: 2746674
Hi badtzmaru,

This assumes R5 is being used and the class is being used within a Notes agent.

The lotus.domino.* classes are used to access the properties and methods of notes.

as with Notes itself, once you have access to the session, you can get access to all the appropriate notes methods and properties.

I have not been able to test this since I no longer have access to Java or R5.

Hope it helps anyway,

Scott.


import lotus.domino.*;

public class OpenNAB extends AgentBase
{
   public void NotesMain ()
   {
       Session sess = null;
       AgentContext agContext = null;
       int p;
       
       try
       {
           sess = getSession();
           agContext = sess.getAgentContext();
           Database dbNames = sess.getDatabase(null,"names.nsf");
           if (dbNames.isOpen())
               {
                 View vwUsers = dbNames.getView("($Users)");
                 Document doc = vwUsers.getFirstDocument();
                 while (doc!=null)
                       {
                           'Perform the action you need to on the document
                           'Get next document
                           doc = vwUsers.getNextDocument();
                       }
           }
           else
               {
                  System.out.println("names.nsf could not be opened");
           }    
       }
       catch (NotesException e)
       {
           System.err.println("NotesException: "+e.text);
           e.printStackTrace();
       }
       catch (Exception e)
       {
           e.printStackTrace();
       }  
   }
}    
0
 
LVL 6

Expert Comment

by:ghassan99
ID: 2747007
This is a sample code to read & write a value to the 'FirstName' field in the person doc in the names.nsf personal address book on the local machine. You can follow up the output in the Java debug window.


import lotus.domino.*;
import java.io.*;
import java.util.*;

public class JavaAgent extends AgentBase {

      public void NotesMain() {

            try {
                  Session session = getSession();
                  AgentContext agentContext = session.getAgentContext();
                  System.out.println("Agent Started");
                  //Database db = session.getDatabase(null,"names.nsf");
                  Database db = agentContext.getCurrentDatabase();
                  View view = db.getView("Contacts");
                  Document doc = view.getFirstDocument();
                  while(doc != null) {
                        String fname = doc.getItemValueString("FirstName");
                        System.out.println(fname);
                                doc.replaceItemValue("FirstName","test value");
                        doc.save(true,false);
                        System.out.println("Doc Saved");
                        }
                        doc = view.getNextDocument(doc);
                  }
            } catch(Exception e) {
                  e.printStackTrace();
            }
      }
}

-Gus
0
 
LVL 6

Accepted Solution

by:
ghassan99 earned 100 total points
ID: 2747013
Sorry the formatting was lost, here it is again:

This is a sample code to read & write a value to the 'FirstName' field in the person doc in the names.nsf personal address book on the local machine.


import lotus.domino.*;
import java.io.*;
import java.util.*;

public class JavaAgent extends AgentBase {

   public void NotesMain() {

   try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      System.out.println("Agent Started");
      //Database db = session.getDatabase(null,"names.nsf");
      Database db = agentContext.getCurrentDatabase();
      View view = db.getView("Contacts");
      Document doc = view.getFirstDocument();
      while(doc != null) {
         String fname = doc.getItemValueString("FirstName");
         System.out.println(fname);
         doc.replaceItemValue("FirstName","test value");
         doc.save(true,false);
         System.out.println("Doc Saved");
      }
      doc = view.getNextDocument(doc);
   }
   } catch(Exception e) {
      e.printStackTrace();
     }
   }
}

-Gus
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question