I still often see code like 'NotesDocument.form(0)' in LotusScript agents to access the value of a NotesItem. When the item name and the purpose of the item is not as clear as on "form", I prefer using 'NotesDocument.GetItemValue("form")(0)'. This seems to be the safe way to go, as you will always receive a valid return value; no need to check, if the item is available - the only thing you have to consider is the type of the item, i.e. will you receive e.g. a String or a Double.
At least it seems to be that simple - now try composing a document from a form that contains a number field, and add a string to that number field. If you then try to access the value of the field using 'GetItemValue', you will receive - EMPTY. So if you prefer defensive coding (and you should), your code *does* have to look like the following in this case:
Dim res as Variant
res = doc.GetItemValue(itemname)
If isEmpty(res) Then
' oops - wrong data type in item
Elseif cstr(res(0)) = "" Then
' item contains an empty string
Else
' valid - do something with it
End if
About the Author
Marcus Foerster works as Systems Architect for Pentos AG in Munich, Germany. His focus lies on the application side, creating collaboration systems for users, groups and enterprises to get their daily work done. This approach includes integrating complex workflows with intuitive user interfaces, using Lotus Notes/Domino with Adobe Flex and other Web technologies.
Read more in Marcus' blog: http://marcus.foerster.com/blog