Datatribe Softwerks, Ltd.

<< 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.

Comments are currently disabled. Feel free to use the contact form.

Reader Contributions:

No documents found




January, 2010
SMTWTFS
     01 02
03 04 05 06 07 08 09
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Articles by Month
Articles by Category
Features Downloads
Recommended