Anbei mein toller Agent. ;)
Verbesserungsvorschläge willkommen!
:)
Sub Initialize()
%REM
Der Agent findet doppelte Dokumente (mit dem gleichen Wert im PlainText-Feld "Meins")
in der Datenbank und versendet die Mail(s) darüber.
Ansicht "(AllDouble)" sortiert nach erster Spalte "Meins" notwendig.
%END REM
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim docOne As NotesDocument 'das erste Dokument in Ansicht
Dim docTwo As NotesDocument 'das nächste Dokument in Ansicht
Dim entryOne As NotesViewEntry 'das erste ViewEntry in Ansicht
Dim entryTwo As NotesViewEntry 'das nächste ViewEntry in Ansicht
Dim vec As NotesViewEntryCollection
Dim countDouble As Integer
Set db = session.CurrentDatabase
Dim serverName As String
If session.IsOnServer Then
serverName = db.Server
Else
serverName = "lokal"
End If
countDouble = 1
Set view = db.GetView( "(AllDouble)" )
view.AutoUpdate = False
Set vec = view.AllEntries
Set entryOne = vec.GetFirstEntry()
Set docOne = entryOne.Document
Dim text1 As String
Dim text2 As String
While Not (docOne Is Nothing)
text1 = "Agent fand " & countDouble & " doppelte Dokumente " & text2 & _
" in Datenbank '" & db.title & "' auf " & serverName
Set entryTwo = vec.GetNextEntry(entryOne)
'Kein weiteres Dokument in Ansicht vorhanden
If entryTwo Is Nothing Then
If countDouble > 1 Then 'Zumindest ein doppeltes Dokument wurde gefunden
Set doc = New NotesDocument(db)
doc.Subject = "Doppelte Dokumente in " & db.title & " !"
doc.Body = text1
Call doc.Send( False, "Bruce Willis/World" )
End If
Exit Sub
End If
Set docTwo = entryTwo.Document
'Ein (oder noch ein) doppeltes Dokument vorhanden
If docOne.Meins(0) = docTwo.Meins(0) Then
countDouble = countDouble + 1
text2 = docOne.Meins(0)
End If
'Zumindest ein doppeltes Dokument wurde gefunden, das nächste Dokument ist aber kein doppeltes mehr
If countDouble > 1 And (docOne.Meins(0) <> docTwo.Meins(0)) Then
Set doc = New NotesDocument(db)
doc.Subject = "Doppelte Dokumente in " & db.title & " !"
doc.Body = text1
Call doc.Send( False, "Bruce Willis/World" )
countDouble = 1
End If
Set entryOne = vec.GetNextEntry(entryOne)
Set docOne = entryOne.Document
Wend
End Sub
Gruß
Leo
Noch kürzer und ohne Zugriff auf NotesDocument:
Sub Initialize()
%REM
Der Agent findet doppelte Dokumente (mit dem gleichen Wert im PlainText-Feld "Meins")
in der Datenbank und versendet die Mail(s) darüber.
Ansicht "(AllDouble)" sortiert nach erster Spalte "Meins" notwendig.
%END REM
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim entryOne As NotesViewEntry 'das erste ViewEntry in Ansicht
Dim entryTwo As NotesViewEntry 'das nächste ViewEntry in Ansicht
Dim vec As NotesViewEntryCollection
Dim countDouble As Integer
Set db = session.CurrentDatabase
Dim serverName As String
If session.IsOnServer Then
serverName = db.Server
Else
serverName = "lokal"
End If
countDouble = 1
Set view = db.GetView( "(AllDouble)" )
view.AutoUpdate = False
Set vec = view.AllEntries
Set entryOne = vec.GetFirstEntry()
Dim text1 As String
Dim text2 As String
While Not (entryOne Is Nothing)
text1 = "Agent fand " & countDouble & " doppelte Dokumente " & text2 & _
" in Datenbank '" & db.title & "' auf " & serverName
Set entryTwo = vec.GetNextEntry(entryOne)
'Kein weiteres Dokument in Ansicht vorhanden
If entryTwo Is Nothing Then
If countDouble > 1 Then 'Zumindest ein doppeltes Dokument wurde gefunden
Set doc = New NotesDocument(db)
doc.Subject = "Doppelte Dokumente in " & db.title & " !"
doc.Body = text1
Call doc.Send( False, "Bruce Willis/World" )
End If
Exit Sub
End If
'Ein (oder noch ein) doppeltes Dokument vorhanden
If entryOne.ColumnValues(0) = entryTwo.ColumnValues(0) Then
countDouble = countDouble + 1
text2 = entryOne.ColumnValues(0)
End If
'Zumindest ein doppeltes Dokument wurde gefunden, das nächste Dokument ist aber kein doppeltes mehr
If countDouble > 1 And (entryOne.ColumnValues(0) <> entryTwo.ColumnValues(0)) Then
Set doc = New NotesDocument(db)
doc.Subject = "Doppelte Dokumente in " & db.title & " !"
doc.Body = text1
Call doc.Send( False, "Bruce Willis/World" )
countDouble = 1
End If
Set entryOne = vec.GetNextEntry(entryOne)
Wend
End Sub