Subject: Comparison of values
Its not completely clear from your post what you are tyring to do. I guess since you mention retrieving document without GetDocumentByKey that you want to locate documents in the database that have a status that matches ‘On’.
There are several ways to do this, each with difference performance in different contexts. The choice depends on the size of your database, how many documents might match the comparison, whether you can change the design of the source database and so on.
First we need to see how to do the comparison. It is easiest to do this with Formula language.
If your Status always begins with “On”, you can do a @Left test:
@left( Status; 2 ) = “On”
( or @left( Status; 3 ) = "On " if you want to exclude statuses that might begin with longer words, such as “Onion” )
If “On” could appear somewhere else in the Status string, you will need to use @Contains. Take a look at the help documentation, and remember that it is case-sensitive.
Now, how can we use this to select documents?
All the approaches below assume that you might find multiple matches for the comparison. Depending on your application requirements you could process all the matching documents or just the first one.
The obvious option is that we could build a view that uses the @left() comparison above as the selection formula. This will only contain documents that match the ‘On’ status. Your code can then just retrieve documents from that view. Job done, and with the best performance.
If you can not create a new view, you could use a database search in lotuscript. This can be much slower.
set dc = db.search( {@left(Status;2)="On"}, nothing, 0 )
This will return a document collection that you can iterate though.
There are also some techniques that use Lotuscript only. You could iterate through an existing view that contains candidate documents and do a lotuscript comparison on each:
set view = db.getView( “MyView” )
set doc = view.getFirstDocument()
while not doc is nothing
status = doc.getItemValue( “Status” )(0)
if( left$( status, 2 ) = “On” ) then
'do something with the document
end if
set doc = view.getNextDocument( doc )
wend
There is an equivalent loop using db.AllDocuments which you could use if there is no suitable view, but you will be iterating through the whole database.
Each of the techniques above will be better or worse depending on the scale of your particular application. If you are just learning, I recommend that you try a few different ways of doing things and see what performance results you get. This is the best way to build your expertise in Notes.