replaceItemValue (NotesDocument - JavaScript)

Replaces all items of the specified name with one new item, which is assigned the specified value.

Defined in

NotesDocument

Syntax

replaceItemValue(name:string, value:any) : NotesItem
Parameter Description
name The name of the item or items you want to replace.
value The value of the new item.
The data type of the item depends on the data type of the value as follows:
Data type of value Resulting Item
string Text
int Number
double Number
NotesDateTime Date-time item
java.util.Vector with string, int, double, or NotesDateTime elements Multi-value text, number, or date-time item
NotesItem Same data type as the NotesItem
Return value Description
NotesItem The new item, which replaces all previous items with the same name.

Usage

If the document does not contain an item with the specified name, this method creates a new item and adds it to the document.

To keep the changes, you must call save after calling replaceItemValue.

The IsSummary property of the new item defaults to true, which means that the item value can be displayed in a view or folder.

Do not use this method to replace the value of a rich text item (or MIME entity) unless you want to change it to a text item. To replace the contents of a rich text item, use NotesDocument.removeItem or NotesItem.remove to delete the old item, NotesDocument.createRichTextItem to create a new one with the same name, and NotesRichTextItem.appendText and other methods to provide the new content.

Examples

This button adds a value to a numeric multi-value item in the current document.
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem("quantity")) {
	var quantities:java.util.Vector = doc.getItemValue("quantity");
	if (quantities.add(requestScope.queryn)) {
		doc.replaceItemValue("quantity", quantities);
		doc.save();
		requestScope.status = "Quantity item replaced";
	} else {
		requestScope.status = "Unable to replace quantity item";
	}
} else {
	doc.appendItemValue("quantity", requestScope.queryn);
	doc.save();
	requestScope.status = "New quantity item added";
}