Update 3-server connection records with one click

Update 3-server connection records with one click

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.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

is an excerpt from the script:

       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