[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Writing to address book via java agent

Posted on 2000-04-22
9
Medium Priority
?
305 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 300 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

872 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