• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 597
  • Last Modified:

Printing attachments in the protected area of a form.

We receive Faxes from a Right Fax server into our Lotus Notes inbox.  We need an agent that will print the fax attachments without having to individually open each email.  The problem, however, is that the faxes are not attached to the email "Body" but are in a "protected area of the form", thus, the normal method of creating a rich text navigator will not work.  The below code being an example:
               

                Dim rtitem As notesrichtextitem
     
     If doc Is Nothing Then Exit Sub
     If doc.HasItem ("Body") = False Then Exit Sub                                                            
     Set rtitem = doc.GetFirstItem( "Body" )      
     If ( rtitem.Type = RICHTEXT ) = False Then Exit Sub
     If Isempty(rtitem.EmbeddedObjects) Then Exit Sub
     
     Forall o In rtitem.EmbeddedObjects
          If ( o.Type = EMBED_ATTACHMENT ) Then
               Call PrintAttachment (o)
          End If
     End Forall

I do not know how to get at the attachments if they are not in the email body.  When I throw the Lotus Script in debug, I can see the attachments in the document as $FILE items, but they are NotesItems, not rich text items, which leaves me without the embeddedobjects method.  I am at a loss for what to do?  Thank you.
0
druss23
Asked:
druss23
  • 5
  • 2
1 Solution
 
marilyngCommented:
Try the document embedded objects method.. with $file you can get the filename, the document embedded objects will collect all $file, and you can extract from there or launch.

Search on NotesDocument properties, I think (Sorry, not at a Notes Computer today)
0
 
marilyngCommented:
Yeah,

Sub Initialize
  Dim db As NotesDatabase
  Dim view As NotesView
  Dim doc As NotesDocument
  Set db = New NotesDatabase( "SanFrancisco", "hill.nsf" )
  Set view = db.GetView( "All Documents" )
  Set doc = view.GetLastDocument
  If doc.HasEmbedded Then
    Forall o In doc.EmbeddedObjects
      Messagebox( o.Name )
    End Forall
  Else
    Messagebox "No embedded objects found"
  End If
End Sub

from the Embedded Objects property of NotesDocument
0
 
druss23Author Commented:
Thank you for the reply.  I receive a type mismatch when running the above code on the Forall line.  I believe this is because the embeddedobjects method in the notesDocument class does not deal with File attachments, everything we receive is a file attachment, it is simply not attached in the body.  From the Notes help about this method in NotesDocument:
Unlike the EmbeddedObjects property in NotesRichTextItem, this property does not include file attachments.  
We are forced to use the embeddedobjects property in NotesRichTextItem, since it is the only one that returns file attachments types.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
marilyngCommented:
No, i don't believe that's the reason, I copied a sample file from the Designer Help, and they typically don't instantiate objects or properties.  Nor do they check for the existance of the properties. :)

So, for instance,
You would need sonething like this:

Dim session as New Notessession
Dim db as Notesdatbase
set db = session.currentdatbase
dim view as Notesview
set view = db.getView("my viewname")
if view is nothing then
 msgbox "Sorry, view not found"
  exit sub
end if
set doc = view.getfirstdocument
while not doc is nothing
   if doc.hasEmbedded then
         forall o in doc.embeddedObjects
             If ( o.Type = EMBED_ATTACHMENT ) Then
                    Call o.ExtractFile( "c:\samples\" & o.Source )
              end if
end forall

set doc = view.getNextDocument(doc)
wend


You need to adjust it.  Are you lotusscript capable?  If not, I will adjust for you, but am not at a Notes computer right now.  

I believe it the instructions for the embedded object that you're seeing is for java, not for the NotesDocument class in LotusScript.  I say this, because I use the doc embedded to detach all attachments from a document when they're not embedded in the RichText field.  So, you can use the rtfield, or the plain doc attachments.  You could probably use the doc.getAttachment( using the $file = filename of the attachment)


Here's another way:  http://www.experts-exchange.com/Applications/Email/Lotus_Notes_Domino/Q_11228338.html?query=embeddedobject&topics=133

when I get home, I will see what I can do to pull a snippet for you.

0
 
marilyngCommented:
Ok here is the exact quote:  Unlike the EmbeddedObjects property in NotesRichTextItem, this property does not include file attachments, nor OLE/1 objects created in Notes Release 3.  <<< NOtes Release 3 is the operative phrase here.

Here is a quick and dirty snippet that I had:  (paste into an agent, and run on selected documents)

Sub Initialize
      'Add your correct filepath here..........................
      Const FILEPATH = "C:\Temp\"
      Const DEFAULTEXT = ".txt"
      '................................................................................
      Dim Session As New NotesSession
      Dim db As NotesDatabase
      Set db = session.currentdatabase
      Dim doc As NotesDocument
      Dim coll As NotesDocumentCollection
      Set coll = db.unprocesseddocuments
      
      Dim count As Integer
      Dim NumAttachments As Variant
      Dim attachmentNames As Variant
      Dim strAttachments As String
      Dim formatString As String, filename As String
      Dim object As NotesEmbeddedObject
      Const NumMacro = {@Attachments}
      Const NameMacro = {@AttachmentNames}
      If coll.count <1 Then Exit Sub
      Set doc = coll.getfirstdocument
      While Not doc Is Nothing
            With doc
                  NumAttachments = Evaluate(NumMacro,Doc)
                  AttachmentNames = Evaluate(NameMacro,Doc)                  
                  If doc.HasEmbedded Then
                        If Isarray(attachmentNames) Then
                              Forall a In attachmentNames
                                    If Len(a)<>"" Then
                                          Set object = doc.GetAttachment(a)
                                          If Not object Is Nothing Then
                                                'Making sure I don't overwrite the files, you can do this with a date, too.
                                                count = count +1
                                                FileName = object.Source
                                                If Instr(1, filename, ".", 5)>0 Then
                                        'the attachment has a file extension leave as is.      
                                                      formatString = FILEPATH + Format(count,"00") + "_" + filename
                                                Else
                                                      'I'm adding a file extension...
                                                      formatString = FILEPATH  + Format(count,"00") + "_" + filename + DEFAULTEXT
                                                End If                                                
                                                Call object.ExtractFile(formatString)            
                                                strAttachments = strAttachments + filename + Chr(13)
                                                Print "Detaching " + formatstring + " ..."
                                                'Optional you can delete the attachement and save the file
                                                'However, don't do this if your view collects on attachments else
                                                'you'll lose the pointer
                                                'Call object.Remove
                                                'doc.save True, False, True
                                                '............................................End Optional
                                          End If
                                    End If
                              End Forall
                        End If
                  End If
            End With
            Redim NumAttachments(0)
            Redim AttachmentNames(0)            
            Set doc = coll.GetNextDocument(doc)
      Wend
      
      If Not coll Is Nothing Then Set coll = Nothing
      
      Msgbox {Detached: } + Cstr(count) + { attachments.} + Chr(13) +_
      strAttachments,,"Done"      
End Sub
0
 
druss23Author Commented:
The operative phrase applies to the second condition (the OLE object).  This is further illustrated in the example section of this same page, which is a little more explicit and not as ambiguously worded.  From the example section:

EmbeddedObjects does not return the Ami Pro document because the object was created in Notes Release 3. It does not return castle.bmp because castle.bmp is a file attachment.

Your code above works (using the GetAttachment method rather than the EmbeddedObject method), and this is what we ultimately will use!  Thank you for your help.
0
 
marilyngCommented:
Yeah, you have to jump through hoops (some minor ones) to grab the ole object on the document, when I was in a hurry, I did this snippet to grab it fast.  Figured it would be of assistance to you, too. :)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now