Files gets moved from RT Field to $File and EmbedObject

Hello –

I have a java agent that it attaches a file and creates a RT Field. When it does that, the field becomes a text field and the file is attached in the $Field. Any help would be appreciated.

  EmbeddedObject eo = orderDoc.getAttachment(fname);

  eo.remove();

  orderDoc.removeItem("Attachments");



  // Attach new file to Notes doc

  if (debug) System.out.println("attach new file");

  RichTextItem rtitm = orderDoc.createRichTextItem("Attachments");

  

  if (debug) System.out.println("embed object: [file path]" + ff.getFPath());

  if (debug) System.out.println("embed object: [fname]" + fname);

  eo = rtitm.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, ff.getFPath(), fname);

orderDoc.save();