Hallo zusammen,
auch nach Durchforsten des Forums komm´ ich einfach nicht mehr weiter.
Ich möchte anhand eines Doc-Links das entsprechende Dokument suchen und die dort befindlichen Anhänge in ein neues Dokument hängen und per Mail wieder versenden.
Soweit zur Theorie.
Mein Code funktioniert soweit, wenn ich ihn mit dem Debugger ausführe. Läuft der Agent jedoch periodisch gestartet, so bekomme ich zwar eine Mail, aber keine Anhänge mit.
Hat mir da jemand vielleicht einen Tipp?
Sub SucheDoc
Dim session As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim col As NotesDocumentCollection
Dim rtitem As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtlink As NotesRichTextDocLink
Dim doc As NotesDocument
Dim unid As String
Set session = New NotesSession
Set db = session.CurrentDatabase
Dim linkDb As New NotesDatabase("", "")
Dim linkDoc As NotesDocument
Dim tempDoc As NotesDocument
Dim linkServer As String
Dim linkDBID As String
Dim linkViewID As String
Dim linkDocID As String
Dim MDoc As NotesDocument
Dim MRTItem As NotesRichTextItem
Set view = db.GetView("($All)")
Set doc = view.GetFirstDocument 'Doc mit Doc-Link
While Not (doc Is Nothing)
Set rtitem = doc.GetFirstItem("Body")
Set rtnav = rtitem.CreateNavigator
Set rtlink = rtnav.GetFirstElement(RTELEM_TYPE_DOCLINK)
linkServer = rtlink.ServerHint
linkViewID = rtlink.ViewUnID
linkDBID = rtlink.DBReplicaID
linkDocID = rtlink.DocUnID
If linkDB.isopen Then
Goto SPRUNG
Else
Call linkDb.OpenByReplicaID(linkServer, linkDBID )
End If
SPRUNG:
Set linkDoc = linkDB.GetDocumentByUNID(linkDocID)
Set tempDoc = db.CreateDocument
Set MDoc = New NotesDocument( db )
If linkDoc.HasEmbedded Then
Call linkDoc.CopyAllItems( tempDoc, True )
Forall item In tempDoc.Items
If Not (Ucase(item.Name) = "$FILE") Then
tempDoc.RemoveItem (item.Name)
End If
End Forall
Call tempDoc.CopyAllItems(MDoc)
MDoc.Subject = "Angeforderte Dokumente "
Set MRTItem = MDoc.CreateRichTextItem("body")
Call MRtItem.AppendText("Hier die angeforderten Dokumente: ")
MDoc.Form = "Memo"
MDoc.SendTo = doc.GetItemValue("From")
Else
MDoc.Subject = "Angeforderte Dokumente konnten nicht ermittelt werden"
Set MRTItem = MDoc.CreateRichTextItem("body")
Call MRtItem.AppendText("Ihre angeforderten Dokumente konnten nicht ermittelt werden. Eventuell beinhaltet das Zieldokument keine Anhänge. ")
MDoc.Form = "Memo"
MDoc.SendTo = doc.GetItemValue("From")
End If
Call MDoc.Send( False )
Set doc = View.GetNextDocument(doc)
Wend
Set doc = view.GetFirstDocument
While Not (doc Is Nothing)
Call doc.RemovePermanently(True)
Set doc = view.GetFirstDocument
Wend
End Sub
Gruß, Freezer
Läuft der Code, wenn Du diesen Agenten manuell startest?
Der Code läuft manuell angestartet zumindest soweit, dass er mir den ersten Anhang zuschickt. Kommen mehrere Felder mit dem Namen $FILE vor, so nimmt er immer das erste Feld.
Beim periodischen Start bin ich mittlerweile so weit, dass ich herausgefunden habe, an welcher Stelle es liegen könnte, nämlich hier
...
If linkDoc.HasEmbedded Then
Call linkDoc.CopyAllItems( tempDoc, True )
Forall item In tempDoc.Items
If Not (Ucase(item.Name) = "$FILE") Then
tempDoc.RemoveItem (item.Name)
End If
End Forall
Call tempDoc.CopyAllItems(MDoc) '<= hier hängt´s wohl
MDoc.Subject = "Angeforderte Dokumente "
Set MRTItem = MDoc.CreateRichTextItem("body")
Call MRtItem.AppendText("Hier die angeforderten Dokumente: ")
Es werden offensichtlich keine $FILE - Felder von "tempDoc" nach "MDoc" kopiert, nachdem andere Felder aus "tempDoc" gelöscht wurden.
Aber warum denn nur :-:
Freezer