Manage Learn to apply best practices and optimize your operations.

Enter zip code, get city and state using LotusScript

With this LotusScript tip, the city and state fields in an application will automatically be filled when a user enters the proper zip code.

This tip works if you have an application that required an address, city, state and zip code. If you ask for the zip code first and pass it to a Web service (as shown below), it will bring back the city and state, thus allowing you to populate that information for the user.

'Put this in the Existing event of the Zip code
 field or where ever you want to trigger it from
 Dim s As New notessession
 Dim ws As New NotesUIWorkspace
 Dim db As NotesDatabase
 Dim view As NotesView 
 Dim uidoc As NotesUIDocument
 Dim doc As NotesDocument
 Dim sourceFile As Variant
 Dim showReturn As String
 Dim strGetZip As String
 
 Set db = s.CurrentDatabase
 Set uidoc = ws.CurrentDocument
 Set doc = uidoc.Document
 
 strGetZip = doc.Zip(0)
 showReturn = getCityState(strGetZip)


Function getCityState(strZip1 As String) As Variant
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim dbLK As NotesDatabase
 Dim viewLK As NotesView
 Dim docLK As NotesDocument 
 Dim xmlapp As Variant
 Dim sReturn1 As Variant
 Dim strState As String
 
 Set db = s.CurrentDatabase
 sourceFile="http://www.webservicex.net/
uszip.asmx/GetInfoByZIP?USZip=" + strZip1
 Set xmlapp = CreateObject("Microsoft.XMLDOM")
 xmlapp.async = False
 xmlapp.load(sourceFile)
 
 doc.City = ElementsByTagName2(xmlapp,"CITY")
 strState = ElementsByTagName2(xmlapp,"STATE")
 
 Set dbLK = s.GetDatabase(db.Server,"LookupGLV.nsf")
 Set viewLK = dbLK.GetView ("LKbyStates5" )
 Set docLK = viewLK.GetDocumentByKey (strState)
 
 doc.State = docLK.spState(0)
 
End Function


Function  ElementsByTagName2(xmlapp,Tag As String)As String
 
 On Error Goto errHandle
 
 Dim XMLList() As String
 Dim x As Variant
 Dim i As Integer
 
 Set x = xmlapp.getElementsByTagName(Tag)
 Redim XMLList(1 To x.length)
 For i = 1 To x.length
  XMLList(i)=(x.item(i-1).text)
 Next
 ElementsByTagName2 = XMLList(1)
 Exit Function
 
errHandle:
 ElementsByTagName2 = 0
 Resume Next
End Function

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

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

Dig Deeper on LotusScript

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

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 ...

SearchDataCenter

SearchContentManagement

Close