Tip #5: using GetDocumentByKey with a date key


How can you use the LotusScript GetDocumentByKey method of the NotesView class to search for a key which is based on a date?

In order to properly search for a date value, you must use the LotusScript Format function. Why? Because views in Notes are "zero-filled" when it comes to date values, whereas Lotusscript does not zero-fill dates (i.e. the date value in a view "21 09 2002" becomes "21 9 2002" in Lotusscript.

The solution of course is to use the Format function, as this will zero-fill yer date for you. For example, assuming my document (docBen) has a date / time field in it called "dateTweaked", and I want to search for another document with the same date, contained within the view "Bens_View":

Dim vwThis As NotesView
Dim docBen As NotesDocument
Dim doc As NotesDocument
Dim strKeyValue As String

' // … Meanwhile, get a handle on the view and docBen objects …

strKeyValue = Format(docBen.dateTweaked(0),"dd/mm/yyyy")
Set doc = vwThis.GetDocumentByKey(strKeyValue)

Comments on this post are now closed.


I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.