getFirstItem (NotesDocument - JavaScript™)
Returns the first item of a specified name in a document.
Defined in
NotesDocumentSyntax
getFirstItem(name:string) : NotesItem
Parameter | Description |
---|---|
name |
The name of the item you want to find. |
Return value | Description |
---|---|
NotesItem |
The first item with the name. Returns null if the document does not contain an item with the 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 NotesDocument 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.
Examples
This button dumps information from all the documents in the current database.try {
var dc:NotesDocumentCollection = database.getAllDocuments();
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
var subject:NotesItem = doc.getFirstItem("Subject");
if (subject == null) {
requestScope.status += "\n[ No subject ]";
} else {
requestScope.status += "\n[ " + subject.getText() + " ]";
}
var body:NotesItem = doc.getFirstItem("Body");
if (body == null) {
requestScope.status += "\n[ No body ]";
} else {
var text:string = body.getText(256);
requestScope.status += "\n" + text;
}
var tmpdoc = dc.getNextDocument();
doc.recycle(); // recycle to avoid memory problems
doc = tmpdoc;
}
} catch(e) {
requestScope.status = e.toString();
}