LotusScript methods and properties convert a NotesRichTextItem to a NotesItem

Technote (FAQ)


Question

An agent acting on a Rich Text field somehow converts the field to a Text field. You are able to see this change using the LotusScript Debugger. The NotesRichTextItem object's Type value initially reflects a 1 (RICHTEXT). After the agent runs, the Debugger indicates the type for the object as 1280 (TEXT).

When a NotesRichTextItem is converted to a NotesItem, the methods and properties of the NotesRichTextItem class no longer have an effect on the field. This, in turn, can cause an error such as the following:

    "Instance member <...> does not exist"

The following graphic shows the Data Type as Text although the field was originally Rich Text:

Answer

This situation will occur under three circumstances:

1. Using the ReplaceItemValue method (of the NotesDocument class)

    The following sample script illustrates this issue:
      Dim rtitem as variant
      Set rtitem=doc.getfirstitem("Body")
      Call doc.replaceitemvalue("Body", "Some new text")
    It is documented that the ReplaceItemValue method, when used with a string replacement value, will result in a Text item (Text field).

2. Writing to the Values property (of the NotesItem class):
    The following sample script illustrates this issue:
      Dim rtitem as variant
      Set rtitem=doc.getfirstitem("Body")
      rtitem.values="Some new text"
    The documentation does not clearly indicate this effect. This documentation issue has been reported to Lotus Quality Engineering.

3. When setting the field using extended syntax:
      doc.body="Some new text"
    The documentation does not clearly indicate this effect. This documentation issue has been reported to Lotus Quality Engineering.


How to avoid this issue:

If you need to replace text in a Rich Text field, you must remove the field and then recreate it. This is done using the RemoveItem method (of the NotesDocument class), and by creating a new NotesRichTextItem object.

NOTE: This is the same methodology that must be used to simply set a Rich Text field to a "" (blank) value.

For example:
    ...
    Call doc.removeitem("Body")
    Dim RtItem as New NotesRichTextItem(doc, "Body")
    'The line below would not be needed if one wanted to simply set the field to a blank value ("").
    Call RtItem.AppendText("This is the new RTF value")


To repair documents in this condition:
  • If the document is saved in the user interface, then the resulting Rich Text field will be of the correct type.
  • You can write a script which will recreate the field with the correct type. A code example appears below.

For example:

The code to repair this does the following: Saves the existing text into a temporary variable, removes the incorrectly data-typed Rich Text field, creates a new Rich Text field and then appends the original text information.

The code sample below assumes that the Rich Text field in question is named Body. The sample below does not include the methodology used to access the NotesDocument object 'doc', as there are numerous ways this can be done.

Dim temp As String
Dim temprt As notesrichtextitem
Set temprt = doc.getfirstitem("Body")
temp = temprt.text
Call doc.removeitem("Body")
Dim RtItem As New NotesRichTextItem(doc, "Body")
Call RtItem.AppendText(temp)
Call doc.save(True, True)

Supporting Information:

If you have an incorrectly-typed field as described above, it will cause an error when synching a Palm device.

Excerpt from the Notes on-line help:

ReplaceItemValue method
Replaces all items of the specified name with one new item, which is assigned the specified value. If the document does not contain an item with the specified name, the method creates a new item and adds it to the document.

Defined in
NotesDocument

Syntax
Set notesItem = notesDocument.ReplaceItemValue( itemName$, value )

Parameters:

itemName$
String. The name of the item(s) you want to replace.

value
The value of the new item. The data type of the item depends upon the data type of value, and does not need to match the data type of the old item.

Data type of value Resulting notesItem
String Text item containing value
Array of strings Text item containing each element of value
Integer Number item containing value
Array of integers Number item containing each element of value
Variant of type DATE Time-date item containing value
Array of variants, where each variant is of type DATE Date-time item containing each element of value
NotesTimeDate Date-time item containing the date-time represented by the object
NotesItem Item whose data type matches the NotesItem type and whose value(s) match the NotesItem value(s)

Related information

How to Update Multi-Value Fields or Arrays Via LotusScr
In Document Properties, a Field Has Entries for Both Te

Historical Number

167731

Product Alias/Synonym

Lotus Notes Client
Lotus Domino Designer Client
Notes Designer for Domino

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

IBM Domino Designer

Software version:

6.0, 6.5, 7.0, 8.0, 8.5, 9.0

Operating system(s):

Windows

Reference #:

1101201

Modified date:

2004-09-13

Translate my page

Machine Translation

Content navigation