Manage Learn to apply best practices and optimize your operations.

Copy names.nsf data and manipulate views

Create an agent to run in a custom target database with views based on names.nsf data.

View member feedback to this tip.

My company needed to display data from the public address book in custom views. Instead of creating these views inside the public address book, I created an agent to run in a custom target database with views based on names.nsf data.

The agent deletes all documents in the target database and then retrieves every record in the public address book. I run this agent on schedule each night. Be sure to run it on "All Documents in a database."

I like this agent because you don't have to worry about problems occurring when you upgrade the public address book. Of course, this code can apply to any database you specify.

  Code: Sub Initialize
 Dim session As New NotesSession
 Dim targetdb As NotesDatabase
 Dim sourcedb As NotesDatabase
 Dim sourcecollection As 
NotesDocumentCollection
 Dim dbcollection As NotesDocumentCollection
 
 'sets the source and target databases 
 Set targetdb = session.CurrentDatabase
 Set sourcedb = session.GetDatabase
( "YOURSERVERNAME", "names.nsf" ) 
 
 'removes existing documents from the
 target database
 Set dbcollection = targetdb.AllDocuments
 Call dbcollection.RemoveAll(True)
 
 'Loop through all documents in the source
 database and copy them into the target
 Set sourcecollection = sourcedb.AllDocuments
 Set doc = sourcecollection.GetFirstDocument
 While Not doc Is Nothing
  Call doc.CopyToDatabase( targetdb )
  Set doc = sourcecollection.
GetNextDocument(doc)
 Wend 
 
End Sub

MEMBER FEEDBACK TO THIS TIP

Well, basically it's a good idea not to change the names.nsf design. Alas, there is a drawback. On deleting an and re-retrieving the complete data every night you create lots of replication stubs. Since they are deleted only after 30 days (per default) the database will contain an amount of 30 times the data as replication stubs. This will be a major problem if it comes to replication and consistency checks.

—Joachim N.

******************************************

It is no problem to create additional custom design protected views in the directory even it is derived from the directory template. The only rule to follow is to not modify existing design elements. Adding and then design-protecting additional design elements (especially views) is no problem.

Regarding the code: Each time the agent runs to delete all the existing docs and recreate them new in the target database results in massive deletion stubs and inefficient replication.

—Dietmar D.

******************************************

You may also want to look at the Directory Catalog functionality and add your design elements into that database. It is highly compact (not sure how large a directory you are digesting) and it is designed to be a separate view into your address book. Same caveats for design protecting, but you are taking advantage of Lotus' code instead of or in addition to your own, so you may be better insulated from design changes.

—Annonymous

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Steve Pitcher. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Dig Deeper on Lotus Notes Domino Agents

SearchWindowsServer

Search400

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury

SearchDataCenter

SearchContentManagement

Close