0

I would like to convert a domino document field of Data Type: MIME Part into a Data Type: Rich Text in backend with SSJS or Java?


I have tried to work with

doc.computeWithForm(true, true);
doc.save(true, true);

but this piece of code has no effect.


Hint: I can do this conversion with a notes client in frontend (open and save the document) without any problems.

Any idea? Thanks in advance!

Georg Kastenhofer
  • 1,387
  • 12
  • 32

1 Answers1

5

You may be able to do this as part of the usually-undesirable side effect of automatic MIME-to-CD conversion in the API. For example, code like this will turn the Body field of the first doc in the DB from MIME to composite data:

boolean convertMime = session.isConvertMime();
session.setConvertMime(true);
Document doc = database.getAllDocuments().getFirstDocument();
RichTextItem rtitem = (RichTextItem)doc.getFirstItem("Body");
rtitem.compact();

doc.save();
session.setConvertMime(convertMime);

By making sure that the session is converting MIME (which is true by default, but it's best to maintain any previously-existing value) and then interacting with the MIME_PART item, it will mangle it into CD for you.

Jesse Gallagher
  • 4,461
  • 13
  • 11
  • Thank you very much for your perfect answer! Now it works :) – Georg Kastenhofer Jul 08 '15 at 12:43
  • 2
    For others hitting the same issue I had I just want to add that by setting the convertMime option we managed to get attached files from MIME fields using the embeddedObjects from a standard RT field :-) – John Dalsgaard Jul 12 '15 at 11:03
  • @Jesse Gallagher I've been trying this, but I keep getting a class cast exception when I get the body field: " ClassCastException: org.openntf.domino.impl.Item incompatible with org.openntf.domino.RichTextItem". could this be because of updates in the last year? – Greg Jun 10 '16 at 14:12
  • 1
    It shouldn't be - that sounds more like the item you're dealing with isn't actually a rich-text item. I'd suggest checking the document in question, or adding a test like `Item foo = doc.getFirstItem("Body"); if(foo.getType() == Item.COMPOSITE) { ... }` (I forget if it uses "COMPOSITE" there, but you get the idea). – Jesse Gallagher Jun 11 '16 at 13:46