Use NotesRichTextItem's appendRTItem()
method:
- Read the original Body item into a NotesRichTextItem
- create a new NotesRichTextItem in your new document
- append the original NotesRichTextItem to your new created
This copies also all attachments included in RichText.
Example:
var docOrig:NotesDocument = ...;
var docNew:NotesDocument = database.createDocument();
docNew.replaceItemValue("Form", "Test");
var bodyOrig:NotesRichTextItem = docOrig.getFirstItem("Body");
var bodyNew:NotesRichTextItem = docNew.createRichTextItem("Body");
bodyNew.appendRTItem(bodyOrig);
docNew.save();
Example 2:
Same code embedded in a button of an XPage with data source "document1". The button
- creates a new document with form "Test",
- copies RichText item "Body" with all attachments from current document "document1" to the new document and
- opens an XPage "Test.xsp" for the new created document
<xp:button
value="Create and open new document with a copy of current document's item Body"
id="button1">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action>
<xp:openPage
name="Test.xsp"
target="editDocument">
<xp:this.documentId><![CDATA[#{javascript:
var docOrig:NotesDocument = document1.getDocument();
var docNew:NotesDocument = database.createDocument();
docNew.replaceItemValue("Form", "Test");
var bodyOrig:NotesRichTextItem = docOrig.getFirstItem("Body");
var bodyNew:NotesRichTextItem = docNew.createRichTextItem("Body");
bodyNew.appendRTItem(bodyOrig);
docNew.save();
return docNew.getUniversalID();}]]></xp:this.documentId>
</xp:openPage>
</xp:this.action>
</xp:eventHandler>
</xp:button>
Precondition for both examples: the attachments have to be in current document's item "Body".