Solved

Writing to address book via java agent

Posted on 2000-04-22
9
268 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

24 Experts available now in Live!

Get 1:1 Help Now