It's now a couple of months since I wrote about a Super Useful Set of LotusScript Wrapper Classes, which I've written about on and off since February.
Today I want to share a few more extensions I've made to them, which help massively when it comes to getting documents from views.
Imagine the following use scenario:
Dim factory As New CustomerFactory() Dim coll As CustomerCollection 'Let's get a collection from a view Set coll = factory.GetAll() 'Or you could to this Set coll = factory.GetAllByID() 'Or you could to this
Set coll = factory.GetAllByCountry() 'Or you could to this Set coll = factory.GetCustomersMatching("foo")
This code utilises the following functions in the CustomerFactory class:
Class CustomerFactory As DocumentFactory Private Function FromView(ViewName As String) As CustomerCollection Set FromView = New CustomerCollection(GetViewNavigator(ViewName)) End Function Function GetAll() As CustomerCollection Set GetAll = FromView("AllCustomers") End Function Function GetAllByCity() As CustomerCollection Set GetAllBySite = FromView("CustomersByCity") End Function Function GetAllByCountry() As CustomerCollection Set GetAllBySite = FromView("CustomersByCountry") End Function Function GetAllByStatus() As CustomerCollection Set GetAllByStatus = FromView("CustomersByStatus") End Function Function GetCustomerByID( id As String ) As Customer Set GetCustomerByID = New Customer( GetDocumentByKey( "CustomersByID", id ) ) End Function Function GetCustomersMatching(query As String) As CustomerCollection Set GetCustomersMatching= New CustomerCollection(GetViewEntriesByKey("(LU-CustomersByAllKeys)", query, False)) End Function End Class
In turn the above code relies on a few additions to the base DocumentFactory class:
Class DocumentFactory Function GetViewEntriesByKey(ViewName As String, SearchTerm As Variant, ExactMatch As Boolean) As NotesViewEntryCollection Set GetViewEntriesByKey = GetView(ViewName).Getallentriesbykey(SearchTerm, Exactmatch) End Function Function GetViewNavigator(ViewName As String) As NotesViewNavigator Set GetViewNavigator = GetView(ViewName).Createviewnav() End Function Function GetAllViewEntries(ViewName As String) As NotesViewEntryCollection Set GetViewNavigator = GetView(ViewName).AllEntries End Function Function GetDocumentByKey(ViewName As String, Lookup As Variant) As NotesDocument Set GetDocumentByKey = GetView(ViewName).Getdocumentbykey( Lookup, True ) End Function End Class
What all this does is make it a lot less tiresome to get a handle on document(s) relating to a particular business object (in this case documents based on the "Customer" form). The base DocumentCollection class now has helper functions to get all view entries or simply a view navigator object. It also has a GetDocumentByKey method which defaults the ExactMatch option to True, because it always is, thus saving us passing it in to the call.
I've also been using these classes extensively in a new Domino database I've been lucky enough to create from scratch and have been working on lately. As I've gone along I've been tweaking and extending the classes and now feel they're at a solid point ready for wider use.
I don't want to bang my own drum too much, but they're amazing. You maybe have to use them to see why, but, once you do, there's no going back. If this were ten years ago they'd be almost revolutionary.
Talking of going back; will I ever!? Will I ever be asked to create a new Domino-based web app from scratch? Never say never and all that, but I have a feeling I won't. Which makes it a shame that I developed such a rich and powerful way of working with Notes objects via LotusScript so late in my days with Notes.
Either way, if you're still working with and creating new Notes apps I implore you to give these classes a go. You'll love them.
My plan is to scrub them all a bit, document them better and then share on Github, along with a demo database. Assuming there's interest?