Hello, Here's a looping question that's probably easy but I'm still a bit new to LotusScript. I've developed a button that I send out to end-users that updates server connection documents in their personal address books. (They have DNS problems, thus the need for connection docs)
There are three servers IP addresses that need to be updated. Currently, when users receive the button, they must click the button 3 times to get each record to update. I'd like the script to update all 3-server connection records with just one click. Any ideas?
Below
Requires Free Membership to View
Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.
Dim db As Notesdatabase
Dim view As NotesView
Dim doc As NotesDocument
Set db = New Notesdatabase ("", "names.nsf")
Set view = db.getview("AdvancedConnections")
Set doc = view.getfirstdocument()
'for all the documents in the view
While Not (doc Is Nothing)
If Trim(doc.Destination (0)) = "CN=Server1/OU=Acme1/O=Acme" Then
Call doc.replaceitemvalue( "OptionalNetworkaddress", "10.208.0.40")
Call doc.replaceitemvalue("PhoneNumber", "10.208.0.40")
Call doc.save (True, True)
Set doc = view.getnextdocument(doc)
End If
If Trim(doc.Destination (0)) = "CN=Server2/OU=Acme1/O=Acme" Then
Call doc.replaceitemvalue( "OptionalNetworkaddress", "10.208.96.40")
Call doc.replaceitemvalue("PhoneNumber", "10.208.96.40")
Call doc.save (True,True)
End If
If Trim(doc.Destination (0)) = "CN=Server3/OU=Acme1/O=Acme" Then
Call doc.replaceitemvalue( "OptionalNetworkaddress", "10.208.16.40")
Call doc.replaceitemvalue("PhoneNumber", "10.208.16.40")
Call doc.save (True,True)
End If
'End If
'Go to the next document
Set doc = view.getnextdocument(doc)
Wend
Messagebox "Connection Documents updated", 0, "Update Info"
'If nooffice = "0" Then
' Messagebox "you don't have an office location document"
'End If
End Sub Try this trick for working with a loose collection - build a "List" and loop through its contents - so the list controls the loop, not the collection of connection documents. Use the following code as a starting point:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim DestList List As String
DestList("Server1/Acme1/Acme") = "10.208.0.40"
DestList("Server2/Acme1/Acme") = "10.208.96.40"
DestList("Server3/Acme1/Acme") = "10.208.16.40"
Set db = session.GetDatabase("", "names.nsf", False)
Set view = db.GetView("AdvancedConnections")
ForAll svr In DestList
Set doc = view.GetDocumentByKey(ListTag(svr))
If (doc Is Nothing) Then
Set doc = db.CreateDocument
Doc.Form = "Connection"
Doc.Destination = ListTag(svr)
End If
doc.OptionalNetworkaddress = svr
doc.PhoneNumber = svr
doc.ComputeWithForm(False)
Call doc.save (True, True)
End ForAll This was first published in April 2002