getFirstItem (Document - Java)

Returns the first item of a specified name in a document.

Defined in

Document

Syntax

public Item getFirstItem(String name)
    throws NotesException

Parameters

String name

The name of the item you want to find.

Return value

Item

The first item with name. Returns null if the document does not contain an item with name.

Usage

If multiple items in a document have the same name, programmatic access is limited to the first item. The remaining items yield invalid data. A work-around is to get the first item, process it, remove it, again get the first item (which was the second item), and so on until you process all the items with the same name. If you do not save the document, the items are not actually removed. However, the recommendation is that you avoid creating multiple items with the same name.

If the value of a field is computed for display, the value is not stored as an item and is inaccessible from a Document object. In some cases, you can access the field value another way. For example, if a document has a DateComposed field computed for display with the formula @Created, use getCreated.

Using this method to get rich text items

To get a rich text item, explicitly cast the return value from getFirstItem to RichTextItem.

Document doc;
//...set value of doc...    
RichTextItem rtitem = (RichTextItem)doc.getFirstItem("Body");

Example