2
votes

I have a document which is comming for a scanner. The scanner sends an email to my database and from a view I can access that document and see the attachment and the subject.

Is there a way I can use the attachment and to put it in another document? I managed to send the subject rich text using a sessionScope, but it is not working with the attachements.

In the destination document I have a fileDownloader.

Which would be the best way to do this?

1
How do you create the destination document? Is it out of the source document?poisonedYouth
Yes, it is out of the source document.Florin Pop
Do you want to open the destination document or is it just for saving the data?poisonedYouth
To open it. I am using the doc UNID to get to the document.Florin Pop
Why don't you use the "copyAllItems" method to duplicate your source document and then delete all unnecessary items?poisonedYouth

1 Answers

1
votes

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".