<< LotusScript: Attaching Images | Home | .NET: Paint.net Scan Lines Plug-in>>
LotusScript: getSafeItem
Fri 29 Jan 2010
Another bit for the library. Utilizing a bunch of NotesItems from a document? Document maybe has, maybe has them not? Since it would be repetitive to write tho code to check for each item over and over and painful to write logic to validate each individual property you want to access before using it (and remembering to do so), this simple function does it automatically, creating an empty item for you if none exists.
Function getSafeItem(doc_in As notesdocument, ItemName_in As String) As NotesItem
If doc_in Is Nothing Then Exit Function
If ItemName_in ="" Then Exit Function
If doc_in.HasItem(ItemName_in) Then
Set getSafeItem = doc_in.GetFirstItem(ItemName_in)
Else
Set getSafeItem = doc_in.AppendItemValue (ItemName_in,"")
End If
End Function
With that, your declarations simply become...
Set myItem = getSafeItem(doc,"myItem")
Note that using this method all the time adds a permanent overhead by doubling the calls to the document object you might use to blindly get the item, so if the situation is that the item is for sure there, skip this. If it's in question, use it.