[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Writing to address book via java agent

Posted on 2000-04-22
9
Medium Priority
?
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

649 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