Solved

Writing to address book via java agent

Posted on 2000-04-22
9
271 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
 

Expert Comment

by:sduncan99
ID: 2742564
Can I ask why you are doing it with Java?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lotus Domino - LKMgr Long Held Lock Dump 10 2,684
Lotus notes email code 2 194
Permanent Lotus Notes Connection for all users in a Domino Domain 15 107
@Mailsend 3 39
I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
A short film showing how OnPage and Connectwise integration works.

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now