rtitem.AppendText seems to create multiple fields

Hello,

we want to change part of our outgoing mail content automatically when the user sends it. We want to insert certain words into the text depending on the following content. For example, to insert the first name “Reinhard” between the words “Mr.” and “Gruene”.

I want to do this by using the following script:


Sub Click(Source As Button)

[…]

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Dim ws As New NotesUIWorkspace

[…]

Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document

Dim body As NotesRichTextItem

Dim rtnav As NotesRichTextNavigator

Set body = doc.GetFirstItem(“Body”)

Set rtnav = body.CreateNavigator

If rtnav.FindFirstString(“Gruene”, RT_FIND_CASEINSENSITIVE) Then

Call body.BeginInsert(rtnav)		

Call body.AppendText ("Reinhard ")

Call body.EndInsert		

End If

Call uidoc.Refresh

[…]

End Sub


I know there are no save and close statement, but let me tell what is happening:

I start this script with a button inside the form. If after that I open the property box to have a look at the fields, I see three “Body” fields. One with the Text before “Gruene”, the next with "Reinhard " and the last with the text from “Gruene” forward. When I save this document, only one Body field is left and it has the same content as before the whole action.

I don’t do this very often, so maybe it is just a beginners mistage. Has anyone an idea? Thanks in advance!

Regards

Reinhard Grüne

Subject: rtitem.AppendText seems to create multiple fields

i think your problem is that you are trying to manipulate RTF body field via backend notesdocument which does not work in the way you expectedtake a look at notesuidocument.fieldappendtext and .fieldsettext - they work with RTF fields but probably will not help in your situation

Subject: rtitem.AppendText seems to create multiple fields

It is completely acceptable to have multiple rich text items with the same name (e.g., “Body”). Don’t worry about it.

Subject: RE: rtitem.AppendText seems to create multiple fields

I alredy heard that, but when I look at the document and press F9, my inserted text is not visible and also, when I save the document and reopen it, there is only one Body field left that looks exactly like before (it does NOT contain my inserted text). So it all seems like I never edited the document at all.

Subject: RE: rtitem.AppendText seems to create multiple fields

I missed the fact that you were not saving and re-opening. The uidoc.Refresh is the wrong approach.

Subject: RE: rtitem.AppendText seems to create multiple fields

The fact that I have to save and reopen was the piece of information I was missing. It now works. Thanks!