Domino Code Fragment

Code Name*
LotusScript substitute for @DBLookup
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.220.13.70
Description*
Ever wanted to do a simple @DBLookup in LotusScript? Here's the code to do it
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

Function dbLookup ( view As NotesView, Byval key As String, Byval itemName As String, returnValue As String) As Integer
Dim doc As NotesDocument
Dim tmp As Variant


returnValue=""
dbLookup=True


Set doc=view. getDocumentByKey(key)

If doc Is Nothing Then
dbLookup=False
Else
tmp=doc.getItemValue(itemName)
returnValue=tmp(0)
End If


End Function

You'll notice a few differences from the @DBLookup. Instead of taking a database name and view name, the function takes a NotesView object. This allows you to open the view once and then get as many things from it as you'd like. It performs much better this way. You could easily modify the function to include a NotesDatabase object and view name and open the view inside the function. Also, the function returns true or false with the actual return value in a parameter. This allows you to embed the function in your other script and simply call something like:

If (dbLookup(view, key, itemName, return)) Then
....
Else
Msgbox "Unable to find document with key " & key & "."
End If