I have created an XPages version of a 10 old application that adds richtext (entered) to an existing field. This code sounds like it may help you:
var moveAddBody = function(doc:NotesDocument){
var addRt:NotesMIMEEntity = doc.getMIMEEntity("addBody");
var attFiles:NotesRichTextItem = doc.getFirstItem("attachedFiles");
if(addRt == null && attFiles == null) return;
if(attFiles != null) {
// println("attFiles: " + attFiles.getText() + ", length=" + attFiles.getValueLength());
}
// if(addRt != null && @Length(addRt.getContentAsText().trim()) <= 28) return; // The standard tags in an empty field fills 28 chars
// Something to move...
var tmpDoc:NotesDocument = doc.getParentDatabase().createDocument(); // Never saved - just left in the wind...
var mime:NotesMIMEEntity = tmpDoc.createMIMEEntity("myBody");
var stream:NotesStream = session.createStream();
var formatter = java.text.SimpleDateFormat('yyyy-MM-dd HH:mm');
var time = formatter.format(@Now());
var logLine:String = '<font size="2" color="#008080" face="sans-serif"><b>' + time + " - " + @Name("[Abbreviate]",@UserName()) + '</b></font>';
stream.writeText(logLine);
if(addRt != null && @Length(addRt.getContentAsText().trim()) > 28) {
stream.writeText('<font size="2" face="sans-serif">'); // Enforce "simiilar" font type/size...
stream.writeText(addRt.getContentAsText());
stream.writeText('</font>');
}
mime.setContentFromText(stream, "text/html", NotesMIMEEntity.ENC_NONE);
var prevMime = session.isConvertMime();
session.setConvertMime(true);
tmpDoc.closeMIMEEntities(true,"myBody");
var rt:NotesRichTextItem = doc.getFirstItem("Body");
var body = null;
if (rt != null) {
body = rt.copyItemToDocument(tmpDoc,"Body");
rt.remove();
}
rt = doc.createRichTextItem("Body");
var rtMime:NotesRichTextItem = tmpDoc.getFirstItem("myBody");
rt.appendRTItem(rtMime);
if(attFiles != null) {
if(addRt == null) rt.addNewLine(1);
rt.appendRTItem(attFiles);
attFiles.remove();
}
if(body != null) {
rt.addNewLine(2);
rt.appendRTItem(body);
}
if(addRt != null) {
addRt.remove();
addRt.recycle();
}
session.setConvertMime(prevMime);
return true;
}
You will need to take out some of the code above since it also adds date/time with some formating (compliant with the Notes version before someone whispers "css..." ;-) ). It also handles attachemnts.
Hope you can use it to solve your problem?
/John