Search code examples
lotus-dominolotusscript

Scan all the documents in a View


So, this my code. It gets only the first document. But what I want to do is read a specific document. The view is a collection of usernames and passwords. So, for example : The username is in the 5th document, then the program will scan the view until it finds the right document. Sorry for my poor explanation. I hope you understand my problem.

On Error Goto e
    Dim db As NotesDatabase
    Dim view As NotesView   
    Dim results As Variant
    Dim cmd As String
    Dim d As NotesDocument, flag As Integer, upw As String, uname As String

Set db = source.Database
uname  = Inputbox("Enter Username")

Set view = db.GetView("Registration View")
Set d = view.GetFirstDocument()


'cmd = {@DbLookup("";"48257E00:00089AF5";"RegView";1)}
'results = Evaluate(cmd)
Dim pw As String, un As String
'Forall Username In results
'   Msgbox username(1)
'End Forall
If Not d Is Nothing Then
    un = d.userfield(0)
    pw = d.passfield(0)
    If un <> uname Then
        Msgbox "Username invalid!"
    End If
    If un = uname Then
        upw  = Inputbox("Enter Password")
        If pw <> upw Then
            Msgbox "Password invalid!"
        End If
        If pw = upw Then
            Msgbox "Log In succesful!"
            flag = 1
        End If          
    End If
End If

If flag <> 1 Then Call source.Close()

Exit Sub
e:
    Print Error, Erl

Solution

  • Instead of using view.getFirstDocument you should use view.getDocumentByKey(uname,true) which return the document with the key uname in the first column in the view

    Make sure the first column In the view is set to sorted

    If no document is found using the key then getDocumentByKey returns nothing