Q:

XPages error Item Body already exists

Domino XPages R8.5.3 FP6, any browser. No problems on R9+.
The error occurs on some existing documents while saving, but not on all. There's a rich text field in a database that's being migrated to XPages. New documents work, but on some older documents there is an error. The client won't install R9 right now, so we have to find some sort of solution. 

A:

What we did: the document is checked before it's opened by XPages in the browser. The treatment: the Body field is converted to MIME. Once that's done, the error is gone.
if(SystemData.getNotesBuildVersion()<400) {  // <R9
        if(doc.hasItem("Body") && !doc.hasItem("Converted")) {
            var tmpdoc= database.createDocument();
            doc.getFirstItem("Body").copyItemToDocument(tmpdoc);
            doc.removeItem("Body");
            doc.save(true, false);
            tmpdoc.convertToMIME(3, 0);
            tmpdoc.getFirstItem("Body").copyItemToDocument(doc);
            doc.replaceItemValue("Converted", "1");
            doc.save(true, false);
        }
    }

It's not a perfect solution, but luckily in most cases the text formatting in the rich text field isn't very important.
Hope it helps someone. 

