HCL Notes Trick – GetAllDocumentsBy2Keys

Programming Tips and Tricks Tips-And-Tricks

While developing in IBM/HCL Notes you may stumble across the situations where your search of documents requires more than one key. The custom function placed below provides you with the same facility. Its prototype is pretty simple, it gets the form name, first field name and its key value, and second field name and its key value. It returns the documents matching the specified keys, through a NotesDocumentCollection object.

As you go through the code you may realize that adding more search fields in the function code is not any difficult. Here’s the simple code for you.

Function getAllDocsBy2Keys ( formname As String , field1 As String, value1 As Variant, field2 As String, value2 As Variant ) As NotesDocumentCollection 
	Dim searchString As String 
	searchString = { Form ="}& formname & {" & @text(}& field1 &{) = "}& value1 & {" & @text(}& field2 &{) = "} & value2 & {"}
	Dim dc As NotesDocumentCollection 	
	Dim session As New NotesSession 
	Dim db As NotesDatabase  

	Set db = session.CurrentDatabase 	
	Set dc = db.Search(searchString, Nothing, 0)
	Set getAllDocsBy2Keys = dc			
End Function

We learnt a couple of more things here that we may not necessarily need to create and use lookup view for a search. Secondly we have to build a form selection criteria string, so it mimics creating a view and then using it to lookup documents.

Leave a Reply

Your email address will not be published. Required fields are marked *