I'd like a button script to add server connection documents to a Personal Address Book. Can you help me create...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
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.
Dig Deeper on LotusScript
Related Q&A from Cregg Hardwick
A user wants to know if it's possible for LotusScript to read an attachment in a Notes document without first detaching it. Find out our expert's ...continue reading
Learn about different options using LotusScript code and Formula language to customize the principal field of outgoing Lotus Notes email messages.continue reading
Read about merging cells in a Microsoft Word table using LotusScript and an Excel example, along with the thought process that goes along with it.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.