Q

How to create connection documents for a Lotus Notes Personal Address Book

SearchDomino.com expert Cregg Hardwick explains how to create new or updated connection documents to a Notes/Domino Personal Address Book.

I'd like a button script to add server connection documents to a Personal Address Book. Can you help me create this script?

I've had the same issue come up from time to time.

I wrote a utility several years back that uses stored forms to send "Rollout messages" to clients of newly developed applications. The stored form would present a set of radio buttons, from which the clients could click the nearest Domino server.

Creating connection documents is pretty simple if you understand the fields that are needed, since Lotus Notes uses the same methods for connection documents as it does for any other kind of documents.

Here is a routine that will create new or updated connection documents for any Domino server. Before calling it, you will need to open the user's Personal Address Book and get a handle to their connection document view. Normally, this will be names.nsf in their local data directory, and the view has an alias of "Connections," but the following code will return a handle to their local connections view even in a non-standard situation:

Dim session As New notessession
Dim AddressBook As NotesDatabase
Dim ConnectionView As NotesView 
 
Forall b In session.AddressBooks          
 ' get users private address book
If b.isPrivateaddressbook Then
Set AddressBook =b
Call AddressBook.open("","")
End If
End Forall
Set ConnectionView = AddressBook.GetView("Connections")  ' 
This is the advanced connections views sorted by server name.

Once you have a handle on the connections view in the user's private NAB, creating a new connection record is as easy as creating any other document in Lotus Notes. The fields involved can be gleaned by examining existing documents already in the connections view.

Function CreateConnection(AddessBook As 
notesdatabase,ConnectionView As notesview,
ServerHierachicalName As String,ServerIPAddress 
As String,Comment As String) As String
   'Attempts to create a connection record in the 
users personal N&A. If an error is encountered, will report 
and will not save doc.
Dim ServerNotesName As New notesname
(ServerHierachicalName)
Dim doc As NotesDocument
Dim ldoc As NotesDocument
 
' First try to find an existing connection doc with this server name
Set ldoc=ConnectionView.getdocumentbykey
(ServerNotesName.abbreviated)
 
' Next create a new connection for this 
document with the specified parameters
' Add various fields inferred by examining 
an existing connection document...
Set doc = New NotesDocument(AddessBook) 
' Just in case the connections form does any 
calculations I don't know about.
With doc 
.Form = "local"
doc.Type = "Connection"
.ConnectionType = "0"   
.PortName= "TCPIP"
.Destination = ServerHierachicalName
.ConnectionLocation = "*"
.Source = "*"
.ConnectionRecordFirst = "1"
.OptionalNetworkAddress = ServerIPAddress
End With
Dim rtitem As New notesrichtextitem(doc,"comments")
 Call rtitem.appendtext(comment)
 
 
 If doc.ComputeWithForm(True,False) 
Then   ' Validate and save the new connection...
  If doc.Save(True,False)   Then
' If everything went well, delete the old connection (if any)...
   If Not ldoc Is Nothing Then
' User should have delete access to his/her own personal NAB!
    Call ldoc.remove(True) 
    CreateConnection= "Replaced "+ServerNotesName.abbreviated
   Else
    CreateConnection ="Added "+ServerNotesName.abbreviated
   End If
  Else
   Error 4000, "Error creating "+ServerNotesName.abbreviated
  End If
 Else
  Error 4000, "Error creating "+ServerNotesName.abbreviated
 End If
End Function


Do you have comments on this Ask the Expert Q&A? Let us know.
This was first published in January 2006

Dig deeper on LotusScript

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close