2

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?

Florin Pop
  • 5,105
  • 3
  • 25
  • 58

1 Answers1

1

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

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • I am opening a new document with the button Open Page event, don't need to create one with `database.createDocument()`, and how can I save the body from the previous page and bring it to the new page? – Florin Pop Nov 05 '14 at 11:24
  • You can use the code from Knut to copy the rtItem and save the document (to get the unid). With the unid you can use the Open Page Simple Action to Edit a Document – PoisonedYouth Nov 05 '14 at 12:46
  • This is what I did, but didn't worked. My fileDownloader still didn't had the attachment. – Florin Pop Nov 05 '14 at 13:15