Appendtext - Duplicate Fields

Hi i have a problem where I am creating a new mail message and adding the Body property to which I am appending the body text.

Set L_RTITEM = V_DOC.CreateRichTextItem(“Body”)

 L_RTITEM.AppendText (P_BODY)

I have found that after upgrading to notes 6.5.2 from Notes 5 the AppendText method now duplicates the property. So the email ends up with two Body properties. This is a problem because I have a DLL which accesses the first array of the Body property list .

V_DOCUMENT.GetItemValue(“Body”)(0)

I can not really afford to change the DLL to loop around the Array as changing a DLL causes massive installation problems at many of my clients sites.

I have noticed a few posts where other people have experienced similiar problems. Did anybody find a solution? or does anyone know what version of Notes I will need to upgrade to to solve this issue?

Subject: Appendtext - Duplicate Fields

In short: doc.save() before or after any RT operation in R6.

What is happening is that code which worked in R5 to access or create an RT item, in R6, that code creates a second item of the same name, which 99% of the time breaks the application because it does not “expect” that. After an item.remove() but before doc.save(), the code often acts like the original item is still there, esp in regard to attachments.

In my situations i have added code like:

Test if the item exists.

  1. If it doesn’t exist, create it as rich text, then doc.save(), then work with the item.

  2. If it does exist but is text (checking item.type) then item.remove() it, create the rich-text item, doc.save(), then work with it.

  3. If it exists and it is already rich-text, operations with that item have not caused any problems or “duplicates” for me.

I think that the situation with text-type items occurs during WebQuerySave() for RTFs on new docs that were created on the Web.

If you want to say that the R5 behavior or the R5 app were “wrong”, OK. Fact: At this worldwide company, in the perception of its users, the R6 upgrade broke a ton of working apps.

This client was already migrating away from Notes development. The problems didn’t help reverse that.

Subject: RE: Appendtext - Duplicate Fields

Thankyou Richard for your informative and consise response unlike Andre whose comments were a little offensive and made without any basis of fact.

You are correct Richard that a second item is being created when I use the item.appendtext method. I tried your suggestion of using doc.save however this still resulted in a duplicate Body item being created. However I found that using doc.replaceItemvalue rather than appendtext worked a treat.

Subject: RE: Appendtext - Duplicate Fields

Actually, Andre’s right about Rich Text being stored across multiple items. That’s normal, and your code apparently does not allow for the possibility. Having a glaring error pointed out should not be taken as an insult.

ReplaceItemValue works ONLY because you are redefining the item as a text field. NotesItems are typed by their content, so when you pump plain text into the item, it becomes a plain old text field.

Subject: RE: Appendtext - Duplicate Fields

I’m glad that’s working. But I am curious about the solution.

I think that the CreateRichTextItem() is making the duplicate, so the Save() wouldn’t help. But I would expect the doc.ReplaceItemValue to find the FIRST item and do what one expects to it. I wonder whether there is now an empty, second item in your documents? Did you remove the Create…() call? Just curious.

Subject: RE: Appendtext - Duplicate Fields

There are not duplicate fields. Please be precise. What I think you’re seeing here is two items – not fields – with the same name. This is a normal occurrence in a Notes document, particularly with rich text items. I’m sorry that you didn’t make your DLL flexible enough to deal with all the valid ways of representing the data internally – but when you depend on undocumented behaviors you’re walking on the edge, guy! It’s hard enough to keep all the documented functionality working.

I’m not familiar with the change you’re talking about, and it may be that there’s something you’re doing that’s causing it. Since you don’t show your code it’s hard to know what you might change.

I’m going to guess that you might be able to consolidate the two rt items into one by creating them in a separate document (which you don’t save), then copying them to your memo using CopyItemToDocument. Since LS combines the multiple items into a single item when you access it, I expect it will write them into your document as a single item. Don’t quote me on it though – it’s just an idea to try.